C#中的Type.GetElementType()方法用于返回当前数组,指针或引用类型所包含或引用的对象的Type。
以下是语法-
public abstract Type GetElementType ();
现在让我们看一个实现Type.GetElementType()方法的示例-
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());
}
}输出结果
这将产生以下输出-
Type = System.String
现在让我们来看另一个实现Type.GetElementType()方法的示例-
using System;
public class Demo {
public static void Main(){
Type t1 = typeof(int[,,,, ]);
Type t2 = t1.GetElementType();
Console.WriteLine("Type = "+t2.ToString());
}
}输出结果
这将产生以下输出-
Type = System.Int32