Phương thức Type.GetElementType() trong C# trả về Type của đối tượng được bao gồm hoặc tham chiếu bởi kiểu mảng, con trỏ hoặc tham chiếu hiện tại.
Cú pháp
public abstract Type GetElementType();
Ví dụ 1
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());
}
}
Đầu ra
Type = System.String
Ví dụ 2
using System;
public class Demo
{
public static void Main()
{
Type t1 = typeof(int[,,,, ]);
Type t2 = t1.GetElementType();
Console.WriteLine("Type = " + t2.ToString());
}
}
Đầu ra
Type = System.Int32