Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

RuntimeTypeHandle Structure

Represents a type using an internal metadata token.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

public value class RuntimeTypeHandle : ISerializable
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public final class RuntimeTypeHandle extends ValueType implements ISerializable
Not applicable.

The following example demonstrates how to obtain a RuntimeTypeHandle from a type or from an object, and how to turn the handle back into a type.

using namespace System;
using namespace System::Reflection;
public ref class MyClass1
   int x;

   int MyMethod()
      return x;

int main()
   MyClass1^ myClass1 = gcnew MyClass1;
   // Get the RuntimeTypeHandle from an object.
   RuntimeTypeHandle myRTHFromObject = Type::GetTypeHandle( myClass1 );
   // Get the RuntimeTypeHandle from a type.
   RuntimeTypeHandle myRTHFromType = MyClass1::typeid->TypeHandle;
   Console::WriteLine( "myRTHFromObject.Value: {0}", myRTHFromObject.Value );
   Console::WriteLine( "myRTHFromObject.Type: {0}", myRTHFromObject.GetType() );
   Console::WriteLine( "myRTHFromType.Value: {0}", myRTHFromType.Value );
   Console::WriteLine( "myRTHFromType.Type: {0}", myRTHFromType.GetType() );

import System.*;
import System.Reflection.*;

public class MyClass1
    private int x = 0;

    public int MyMethod()
        return x;
    } //MyMethod
} //MyClass1

public class MyClass2
    public static void main(String[] args)
        MyClass1 myClass1 = new MyClass1();
        // Get the RuntimeTypeHandle from an object.
        RuntimeTypeHandle myRTHFromObject = Type.GetTypeHandle(myClass1);
        // Get the RuntimeTypeHandle from a type.
        RuntimeTypeHandle myRTHFromType = (MyClass1.class.ToType()).

        Console.WriteLine("myRTHFromObject.Value: {0}", myRTHFromObject.
        Console.WriteLine("myRTHFromObject.Type: {0}", myRTHFromObject.
        Console.WriteLine("myRTHFromType.Value: {0}", myRTHFromType.
        Console.WriteLine("myRTHFromType.Type: {0}", myRTHFromType.
} //MyClass2

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0

Community Additions

© 2015 Microsoft