When overridden in a derived class, returns the Type of the object encompassed or referred to by the current array, pointer or reference type.
![]()
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.
This method returns null for the Array class.
The following example demonstrates the Type.GetElementType method.
C# Example
using System; class TestType { public static void Main() { int[] array = {1,2,3}; Type t = array.GetType(); Type t2 = t.GetElementType(); Console.WriteLine("{0} element type is {1}",array, t2.ToString()); TestType newMe = new TestType(); t = newMe.GetType(); t2 = t.GetElementType(); Console.WriteLine("{0} element type is {1}", newMe, t2==null? "null" : t2.ToString()); } }
The output is
System.Int32[] element type is System.Int32