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