Export (0) Print
Expand All
Expand Minimize

TypeCode Enumeration

Specifies the type of an object.

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

[SerializableAttribute]
[ComVisibleAttribute(true)]
public enum TypeCode

Member nameDescription
Supported by the XNA FrameworkSupported by Portable Class LibraryBooleanA simple type representing Boolean values of true or false.
Supported by the XNA FrameworkSupported by Portable Class LibraryByteAn integral type representing unsigned 8-bit integers with values between 0 and 255.
Supported by the XNA FrameworkSupported by Portable Class LibraryCharAn integral type representing unsigned 16-bit integers with values between 0 and 65535. The set of possible values for the Char type corresponds to the Unicode character set.
Supported by the XNA FrameworkSupported by Portable Class LibraryDateTimeA type representing a date and time value.
Supported by the XNA FrameworkDBNullA database null (column) value.
Supported by the XNA FrameworkSupported by Portable Class LibraryDecimalA simple type representing values ranging from 1.0 x 10 -28 to approximately 7.9 x 10 28 with 28-29 significant digits.
Supported by the XNA FrameworkSupported by Portable Class LibraryDoubleA floating point type representing values ranging from approximately 5.0 x 10 -324 to 1.7 x 10 308 with a precision of 15-16 digits.
Supported by the XNA FrameworkSupported by Portable Class LibraryEmptyA null reference.
Supported by the XNA FrameworkSupported by Portable Class LibraryInt16An integral type representing signed 16-bit integers with values between -32768 and 32767.
Supported by the XNA FrameworkSupported by Portable Class LibraryInt32An integral type representing signed 32-bit integers with values between -2147483648 and 2147483647.
Supported by the XNA FrameworkSupported by Portable Class LibraryInt64An integral type representing signed 64-bit integers with values between -9223372036854775808 and 9223372036854775807.
Supported by the XNA FrameworkSupported by Portable Class LibraryObjectA general type representing any reference or value type not explicitly represented by another TypeCode.
Supported by the XNA FrameworkSupported by Portable Class LibrarySByteAn integral type representing signed 8-bit integers with values between -128 and 127.
Supported by the XNA FrameworkSupported by Portable Class LibrarySingleA floating point type representing values ranging from approximately 1.5 x 10 -45 to 3.4 x 10 38 with a precision of 7 digits.
Supported by the XNA FrameworkSupported by Portable Class LibraryStringA sealed class type representing Unicode character strings.
Supported by the XNA FrameworkSupported by Portable Class LibraryUInt16An integral type representing unsigned 16-bit integers with values between 0 and 65535.
Supported by the XNA FrameworkSupported by Portable Class LibraryUInt32An integral type representing unsigned 32-bit integers with values between 0 and 4294967295.
Supported by the XNA FrameworkSupported by Portable Class LibraryUInt64An integral type representing unsigned 64-bit integers with values between 0 and 18446744073709551615.

Call the GetTypeCode method on classes that implement the IConvertible interface to obtain the type code for an instance of that class.

Otherwise, call an object's GetType method to obtain its Type object, then call the Type object's GetTypeCode method to obtain the object's type code.

The following code example demonstrates how the TypeCode enumeration can be used. In a decision block inside the WriteObjectInfo method, the TypeCode of an Object parameter is examined, and an appropriate message is written to the console.

static void WriteObjectInfo(object testObject)
{
    TypeCode    typeCode = Type.GetTypeCode( testObject.GetType() );

    switch( typeCode )
    {
        case TypeCode.Boolean:
            Console.WriteLine("Boolean: {0}", testObject);
            break;

        case TypeCode.Double:
            Console.WriteLine("Double: {0}", testObject);
            break;

        default:
            Console.WriteLine("{0}: {1}", typeCode.ToString(), testObject);
            break;
    }
}

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft