C# TypeInfo TypeHandle
Description
TypeInfo TypeHandle
Gets the handle for the current Type.
Syntax
TypeInfo.TypeHandle
has the following syntax.
public virtual RuntimeTypeHandle TypeHandle { get; }
Example
Gets the handle for the current Type.
using System;/* w ww. j a v a 2 s .c o m*/
using System.Reflection;
class MyClass
{
public int myField = 10;
}
class Type_TypeHandle
{
public static void Main()
{
MyClass myClass = new MyClass();
Type myClassType = myClass.GetType();
RuntimeTypeHandle myClassHandle = myClassType.TypeHandle;
DisplayTypeHandle(myClassHandle);
}
public static void DisplayTypeHandle(RuntimeTypeHandle myTypeHandle)
{
Type myType = Type.GetTypeFromHandle(myTypeHandle);
Console.WriteLine("\nDisplaying the type from the handle:\n");
Console.WriteLine("The type is {0}.", myType.ToString());
}
}
The code above generates the following result.