C# में Type.GetTypeHandle() मेथड का उपयोग किसी निर्दिष्ट ऑब्जेक्ट के Type के लिए हैंडल प्राप्त करने के लिए किया जाता है।
सिंटैक्स
निम्नलिखित सिंटैक्स है -
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