Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Type.GetElementType Method

When overridden in a derived class, returns the Type of the object encompassed or referred to by the current array, pointer or reference type.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

public abstract Type GetElementType ()
public abstract Type GetElementType ()
public abstract function GetElementType () : Type

Return Value

The Type of the object encompassed or referred to by the current array, pointer, or reference type, or a null reference (Nothing in Visual Basic) if the current Type is not an array or a pointer, or is not passed by reference, or represents a generic type or a type parameter in the definition of a generic type or generic method.

This method returns a null reference (Nothing in Visual Basic) for the Array class.

The following example demonstrates using the GetElementType method.

using System;
class TestGetElementType 
{
    public static void Main() 
    {
        int[] array = {1,2,3};
        Type t = array.GetType();
        Type t2 = t.GetElementType();
        Console.WriteLine("The element type of {0} is {1}.",array, t2.ToString());
        TestGetElementType newMe = new TestGetElementType();
        t = newMe.GetType();
        t2 = t.GetElementType();
        Console.WriteLine("The element type of {0} is {1}.", newMe, t2==null? "null" : t2.ToString());
    }
}

import System.*;

class TestGetElementType
{
    public static void main(String[] args)
    {
        int array[] =  { 1, 2, 3 };
        Type t = array.GetType();
        Type t2 = t.GetElementType();
        Console.WriteLine("The element type of {0} is {1}.", array,
            t2.ToString());
        TestGetElementType newMe = new TestGetElementType();
        t = newMe.GetType();
        t2 = t.GetElementType();
        Console.WriteLine("The element type of {0} is {1}.", newMe,
            (t2 == null) ? "null" : t2.ToString());
    } //main
} //TestGetElementType

This code produces the following output:

System.Int32[] element type is System.Int32
    TestGetElementType element type is null

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft