C# में Type.GetTypeHandle() विधि का उपयोग निर्दिष्ट ऑब्जेक्ट के प्रकार के लिए हैंडल प्राप्त करने के लिए किया जाता है।
सिंटैक्स
निम्नलिखित वाक्य रचना है -
public static RuntimeTypeHandle GetTypeHandle (object ob);
ऊपर, ob वह वस्तु है जिसके लिए टाइप हैंडल प्राप्त करना है।
उदाहरण
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
उदाहरण
आइए अब 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);
}
} आउटपुट
यह निम्नलिखित आउटपुट उत्पन्न करेगा -
Attributes = AutoLayout, AnsiClass, Class, Serializable, BeforeFieldInit Type Referenced = System.RuntimeType