Để có được xử lý cho Loại của một đối tượng được chỉ định, mã như sau -
Ví dụ
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);
Console.WriteLine("Type Referenced = "+ type);
}
} Đầu ra
Điều này sẽ tạo ra kết quả sau -
Attributes = AutoLayout, AnsiClass, Class, Serializable, BeforeFieldInit Type Referenced = System.RuntimeType
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(double);
RuntimeTypeHandle typeHandle = Type.GetTypeHandle(type1);
Type type = Type.GetTypeFromHandle(typeHandle);
Console.WriteLine("Attributes = " + type.Attributes);
Console.WriteLine("Type Referenced = "+ type);
}
} Đầu ra
Điều này sẽ tạo ra kết quả sau -
Attributes = AutoLayout, AnsiClass, Class, Serializable, BeforeFieldInit Type Referenced = System.RuntimeType