C# 中的 Type.GetTypeFromHandle() 方法
C# 中的 Type.GetTypeFromHandle() 方法用于获取由指定类型句柄引用的类型。
语法
以下是语法 −
public static Type GetTypeFromHandle (RuntimeTypeHandle handle);
上述代码中,handle 参数是引用该类型的对象。
示例
现在让我们看一个示例来实现 Type.GetTypeFromHandle() 方法 −
using System;
public class Demo {
public static void Main(){
Type type1 = typeof(short);
RuntimeTypeHandle typeHandle = Type.GetTypeHandle(type1);
Type type = Type.GetTypeFromHandle(typeHandle);
Console.WriteLine("Attributes = " + type.Attributes);
}
}输出
将会生成以下输出 −
Attributes = AutoLayout, AnsiClass, Class, Serializable, BeforeFieldInit
示例
现在让我们看另一个示例来实现 Type.GetTypeFromHandle() 方法 −
using System;
public class Demo {
public static void Main(){
Type type1 = typeof(System.Type);
RuntimeTypeHandle typeHandle = Type.GetTypeHandle(type1);
Type type = Type.GetTypeFromHandle(typeHandle);
Console.WriteLine("Attributes = " + type.Attributes);
}
}输出
将会生成以下输出 −
Attributes = AutoLayout, AnsiClass, Class, Serializable, BeforeFieldInit
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP