Gets the Type with the specified name.
Overload List
Gets the Type with the specified name, performing a case-sensitive search.
Supported by the .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;
Gets the Type with the specified name, performing a case-sensitive search and specifying whether to throw an exception if an error occurs while loading the Type.
Supported by the .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;
Gets the Type with the specified name, specifying whether to perform a case-sensitive search and whether to throw an exception if an error occurs while loading the Type.
Supported by the .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;
Inherited from Object.
Supported by the .NET Compact Framework.
[Visual Basic] Overloads Public Function GetType() As Type
[C#] public Type GetType();
[C++] public: Type* GetType();
[JScript] public function GetType() : Type;
Example
[Visual Basic, C#, C++] The following example retrieves the type of System.Int32 and uses that type object to display the FullName property of System.Int32. If a type object refers to an assembly that does not exist, this example throws an exception.
[Visual Basic, C#, C++] Note This example shows how to use one of the overloaded versions of GetType. For other examples that might be available, see the individual overload topics.
[Visual Basic]
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] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
See Also
Type Class | Type Members | System Namespace