The Type.GetElementType() method in C# is used to return the Type of the object encompassed or referred to by the current array, pointer or reference type.
Syntax
Following is the syntax −
public abstract Type GetElementType ();
Example
Let us now see an example to implement the Type.GetElementType() method −
using System;
public class Demo {
public static void Main(){
string[] arr = {"tom", "amit", "kevin", "katie"};
Type t1 = arr.GetType();
Type t2 = t1.GetElementType();
Console.WriteLine("Type = "+t2.ToString());
}
}Output
This will produce the following output −
Type = System.String
Example
Let us now see another example to implement the Type.GetElementType() method −
using System;
public class Demo {
public static void Main(){
Type t1 = typeof(int[,,,, ]);
Type t2 = t1.GetElementType();
Console.WriteLine("Type = "+t2.ToString());
}
}Output
This will produce the following output −
Type = System.Int32