System.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.

Syntax

public abstract Type GetElementType ()

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.

Remarks

This method returns null for the Array class.

Example

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
TestType element type is null

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0