C# Type GetType(String)

Description

Type GetType(String) gets the Type with the specified name, performing a case-sensitive search.

Syntax

Type.GetType(String) has the following syntax.


public static Type GetType(
  string typeName
)

Parameters

Type.GetType(String) has the following parameters.

  • typeName - The assembly-qualified name of the type to get. See AssemblyQualifiedName. If the type is in the currently executing assembly or in Mscorlib.dll, it is sufficient to supply the type name qualified by its namespace.

Returns

Type.GetType(String) method returns The type with the specified name, if found; otherwise, null.

Example

The following example retrieves the type of System.Int32 and uses that type object to display the FullName property of System.Int32.


using System;/* w w  w  . j a  va 2 s. c om*/
namespace MyTypeNameSpace
{
    class MyClass
    {
        public static void Main(string[] arg)
        {
                Type myType1 = Type.GetType("System.Int32");
                Console.WriteLine("The full name is {0}.", myType1.FullName);
                Type myType2 = Type.GetType("NoneSuch", true);
                Console.WriteLine("The full name is {0}.", myType2.FullName);
        }
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version