C#中的Type.GetTypeArray()方法用于获取指定数组中对象的类型。
以下是语法-
public static Type[] GetTypeArray (object[] args);
arg参数是要确定其类型的对象数组。
现在让我们看一个实现Type.GetTypeArray()方法的示例-
using System;
using System.Reflection;
public class Demo {
public static void Main(){
Object[] obj = new Object[5];
obj[0] = 10.20;
obj[1] = 20;
obj[2] = 30;
obj[3] = 40;
obj[4] = "tom";
Type[] type = Type.GetTypeArray(obj);
Console.WriteLine("Types...");
for (int i = 0; i < type.Length; i++)
Console.WriteLine(" {0}", type[i]);
}
}输出结果
这将产生以下输出-
Types... System.Double System.Int32 System.Int32 System.Int32 System.String
现在让我们来看另一个实现Type.GetTypeArray()方法的示例-
using System;
using System.Reflection;
public class Demo {
public static void Main(){
Object[] obj = new Object[5];
obj[0] = 100m;
obj[1] = 20.98;
obj[2] = 30.788m;
obj[3] = 40;
obj[4] = "jack";
Type[] type = Type.GetTypeArray(obj);
Console.WriteLine("Types...");
for (int i = 0; i < type.Length; i++)
Console.WriteLine(" {0}", type[i]);
}
}输出结果
这将产生以下输出-
Types... System.Decimal System.Double System.Decimal System.Int32 System.String