Type.GetTypeHandle メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > Type.GetTypeHandle メソッドの意味・解説 

Type.GetTypeHandle メソッド

指定したオブジェクトTypeハンドル取得します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Shared Function GetTypeHandle
 ( _
    o As Object _
) As RuntimeTypeHandle
Dim o As Object
Dim returnValue As RuntimeTypeHandle

returnValue = Type.GetTypeHandle(o)
public static RuntimeTypeHandle GetTypeHandle
 (
    Object o
)
public:
static RuntimeTypeHandle GetTypeHandle (
    Object^ o
)
public static RuntimeTypeHandle GetTypeHandle
 (
    Object o
)
public static function GetTypeHandle
 (
    o : Object
) : RuntimeTypeHandle

パラメータ

o

Type ハンドル取得対象となる Object

戻り値
指定した ObjectTypeハンドル

解説解説
使用例使用例

クラス MyClass1定義し、そのインスタンス取得してオブジェクトランタイム ハンドル取得する例を次に示します

Imports System
Imports System.Reflection

 _
Public Class MyClass1
   Private x As Integer
 = 0
   
   Public Function MyMethod() As
 Integer
      Return x
   End Function 'MyMethod
End Class 'MyClass1
 _
Public Class MyClass2
   
   Public Shared Sub Main()
      Dim myClass1 As New
 MyClass1()
      
      ' Get the RuntimeTypeHandle from an object.
      Dim myRTHFromObject As RuntimeTypeHandle
 = Type.GetTypeHandle(myClass1)
      ' Get the RuntimeTypeHandle from a type.
      Dim myRTHFromType As RuntimeTypeHandle
 = GetType(MyClass1).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())
   End Sub 'Main 
End Class 'MyClass2
using System;
using System.Reflection;
public class MyClass1
{
    private int x=0;
    public int MyMethod()
    {
        return x;
    }
}
public class MyClass2
{
    public static void Main()
    {
        MyClass1 myClass1 = new MyClass1();

        // Get the RuntimeTypeHandle from an object.
        RuntimeTypeHandle myRTHFromObject = Type.GetTypeHandle(myClass1);
        // Get the RuntimeTypeHandle from a type.
        RuntimeTypeHandle myRTHFromType = typeof(MyClass1).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());

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

public:
   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()).
            get_TypeHandle();

        Console.WriteLine("myRTHFromObject.Value: {0}", myRTHFromObject.
            get_Value());
        Console.WriteLine("myRTHFromObject.Type: {0}", myRTHFromObject.
            GetType());
        Console.WriteLine("myRTHFromType.Value: {0}", myRTHFromType.
            get_Value());
        Console.WriteLine("myRTHFromType.Type: {0}", myRTHFromType.
            GetType());
    }//main 
} //MyClass2
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
Type クラス
Type メンバ
System 名前空間
RuntimeTypeHandle 構造体
TypeHandle
GetTypeFromHandle


このページでは「.NET Framework クラス ライブラリ リファレンス」からType.GetTypeHandle メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からType.GetTypeHandle メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からType.GetTypeHandle メソッド を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「Type.GetTypeHandle メソッド」の関連用語

Type.GetTypeHandle メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



Type.GetTypeHandle メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS