Phương thức Type.GetTypeHandle () trong C # được sử dụng để xử lý Kiểu của một đối tượng được chỉ định.
Cú pháp
Sau đây là cú pháp -
public static RuntimeTypeHandle GetTypeHandle (object ob);
Ở trên, ob là đối tượng để lấy kiểu xử lý.
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ụ
Bây giờ chúng ta hãy xem một ví dụ khác để triển khai phương thức Type.GetTypeHandle () -
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