C# Type GetElementType
Description
Type GetElementType
when overridden in a derived class,
returns the Type of the object encompassed or referred to by the current array,
pointer or reference type.
Syntax
Type.GetElementType
has the following syntax.
public abstract Type GetElementType()
Returns
Type.GetElementType
method returns The Type of the object encompassed or referred to by the current array, pointer,
or reference type, or null 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.
Example
The following example demonstrates using the GetElementType method.
//from w w w. j ava 2 s . com
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());
}
}
The code above generates the following result.