C# 中的 Type.GetTypeArray() 方法
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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP