Phương thức Type.GetTypeFromHandle () trong C # được sử dụng để nhận kiểu được tham chiếu bởi xử lý kiểu đã chỉ định.
Cú pháp
Sau đây là cú pháp -
public static Type GetTypeFromHandle (RuntimeTypeHandle handle);
Ở trên, tham số xử lý là đối tượng tham chiếu đến kiểu.
Ví dụ
Bây giờ chúng ta hãy xem một ví dụ để triển khai phương thức 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);
}
} Đầu ra
Điều này sẽ tạo ra kết quả sau -
Attributes = AutoLayout, AnsiClass, Class, Serializable, BeforeFieldInit
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.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);
}
} Đầu ra
Điều này sẽ tạo ra kết quả sau -
Attributes = AutoLayout, AnsiClass, Class, Serializable, BeforeFieldInit