Share via


Type.GetType メソッド

指定した名前の Type を取得します。

オーバーロードの一覧

大文字と小文字を区別する検索を実行して、指定した名前の Type を取得します。

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Shared Function GetType(String) As Type

[C#] public static Type GetType(string);

[C++] public: static Type* GetType(String*);

[JScript] public static function GetType(String) : Type;

大文字と小文字を区別する検索を実行し、 Type の読み込み中にエラーが発生した場合に例外をスローするかどうかを指定して、指定した名前の Type を取得します。

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Shared Function GetType(String, Boolean) As Type

[C#] public static Type GetType(string, bool);

[C++] public: static Type* GetType(String*, bool);

[JScript] public static function GetType(String, Boolean) : Type;

検索で大文字と小文字を区別するかどうか、および Type の読み込み中にエラーが発生した場合に例外をスローするかどうかを指定して、指定した名前の Type を取得します。

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Shared Function GetType(String, Boolean, Boolean) As Type

[C#] public static Type GetType(string, bool, bool);

[C++] public: static Type* GetType(String*, bool, bool);

[JScript] public static function GetType(String, Boolean, Boolean) : Type;

Object から継承されます。

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Function GetType() As Type

[C#] public Type GetType();

[C++] public: Type* GetType();

[JScript] public function GetType() : Type;

使用例

[Visual Basic, C#, C++] System.Int32 の型を取得し、その型オブジェクトを使用して、 System.Int32FullName プロパティを表示する例を次に示します。型オブジェクトが存在しないアセンブリを参照している場合、この例では例外がスローされます。

[Visual Basic, C#, C++] メモ   ここでは、GetType のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。

 
Imports System
Namespace MyTypeNameSpace
    Class MyClass1
        Public Shared Sub Main()
            Try
                ' Get the type of the specified class.
                Dim myType1 As Type = Type.GetType("System.Int32")
                Console.WriteLine("The full name is {0}.", myType1.FullName)
                ' Since NoneSuch does not exist in this assembly, GetType throws a TypeLoadException.
                Dim myType2 As Type = Type.GetType("NoneSuch", True)
                Console.WriteLine("The full name is {0}.", myType2.FullName)
            Catch e As TypeLoadException
                Console.WriteLine(e.Message.ToString())
            Catch e As Exception
                Console.WriteLine(e.Message.ToString())
            End Try
        End Sub 'Main
    End Class 'MyClass1
End Namespace 'MyTypeNameSpace

[C#] 
using System;
namespace MyTypeNameSpace
{
    class MyClass
    {
        public static void Main(string[] arg)
        {
            try
            {
                // Get the type of a specified class.
                Type myType1 = Type.GetType("System.Int32");
                Console.WriteLine("The full name is {0}.", myType1.FullName);
                // Since NoneSuch does not exist in this assembly, GetType throws a TypeLoadException.
                Type myType2 = Type.GetType("NoneSuch", true);
                Console.WriteLine("The full name is {0}.", myType2.FullName);
            }
            catch(TypeLoadException e)
            {
                Console.WriteLine(e.Message);
            }
            catch(Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
    }
}

[C++] 
#using <mscorlib.dll>

using namespace System;

int main() {
   try {
      // Get the type of a specified class.
      Type*  myType1 = Type::GetType(S"System.Int32");
      Console::WriteLine(S"The full name is {0}.", myType1->FullName);
      // Since NoneSuch does not exist in this assembly, GetType throws a TypeLoadException.
      Type*  myType2 = Type::GetType(S"NoneSuch", true);
      Console::WriteLine(S"The full name is {0}.", myType2->FullName);
   } catch (TypeLoadException* e) {
      Console::WriteLine(e->Message);
   } catch (Exception* e) {
      Console::WriteLine(e->Message);
   }
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

参照

Type クラス | Type メンバ | System 名前空間