C#中获取由指定类型句柄引用的类型
要获取指定类型句柄引用的类型,代码如下-
示例
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
示例
让我们看另一个例子-
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
热门推荐
1 初八祝福语简短语
10 近代生日祝福语简短精辟
11 小姨生日祝福语简短独特
12 朋友花篮开业祝福语简短
13 结婚喜庆的祝福语简短
14 医政科祝福语简短
15 身体康复的祝福语简短
16 感谢父母的简短祝福语
17 职场祝福语大全 简短精辟
18 修祖屋祝福语简短