Để có được kiểu được tham chiếu bởi xử lý kiểu đã chỉ định, mã như sau -
Ví dụ
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);
}
} Đầu ra
Điều này sẽ tạo ra kết quả sau -
Attributes = AutoLayout, AnsiClass, Class, Serializable, BeforeFieldInit
Ví dụ
Hãy để chúng tôi xem một ví dụ khác -
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);
}
} Đầu ra
Điều này sẽ tạo ra kết quả sau -
Attributes = AutoLayout, AnsiClass, Class, Serializable, BeforeFieldInit