ในการรับหมายเลขอ้างอิงสำหรับประเภทของวัตถุที่ระบุ รหัสจะเป็นดังนี้ -
ตัวอย่าง
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);
}
} ผลลัพธ์
สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -
Attributes = AutoLayout, AnsiClass, Class, Serializable, BeforeFieldInit Type Referenced = System.RuntimeType
ตัวอย่าง
เรามาดูตัวอย่างกัน −
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);
}
} ผลลัพธ์
สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -
Attributes = AutoLayout, AnsiClass, Class, Serializable, BeforeFieldInit Type Referenced = System.RuntimeType