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
আরেকটি উদাহরণ (double টাইপের জন্য)
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