Compartilhar via


TypeCode Enumeration

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Specifies the type of an object.

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

Syntax

'Declaration
<ComVisibleAttribute(True)> _
Public Enumeration TypeCode
[ComVisibleAttribute(true)]
public enum TypeCode

Members

Member name Description
Supported by Silverlight for Windows PhoneSupported by Xbox 360 Empty A null reference.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 Object A general type representing any reference or value type not explicitly represented by another TypeCode.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 DBNull A database null (column) value.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 Boolean A simple type representing Boolean values of true or false.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 Char An 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 Silverlight for Windows PhoneSupported by Xbox 360 SByte An integral type representing signed 8-bit integers with values between -128 and 127.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 Byte An integral type representing unsigned 8-bit integers with values between 0 and 255.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 Int16 An integral type representing signed 16-bit integers with values between -32768 and 32767.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 UInt16 An integral type representing unsigned 16-bit integers with values between 0 and 65535.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 Int32 An integral type representing signed 32-bit integers with values between -2147483648 and 2147483647.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 UInt32 An integral type representing unsigned 32-bit integers with values between 0 and 4294967295.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 Int64 An integral type representing signed 64-bit integers with values between -9223372036854775808 and 9223372036854775807.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 UInt64 An integral type representing unsigned 64-bit integers with values between 0 and 18446744073709551615.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 Single A 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 Silverlight for Windows PhoneSupported by Xbox 360 Double A 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 Silverlight for Windows PhoneSupported by Xbox 360 Decimal A 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 Silverlight for Windows PhoneSupported by Xbox 360 DateTime A type representing a date and time value.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 String A sealed class type representing Unicode character strings.

Remarks

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.

Examples

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 displayed.

Sub WriteObjectInfo(ByVal outputBlock As System.Windows.Controls.TextBlock, ByVal testObject As Object)
   Dim typeCode As TypeCode = Type.GetTypeCode(testObject.GetType())

   Select Case typeCode
      Case typeCode.Boolean
         outputBlock.Text += String.Format("Boolean: {0}", testObject) & vbCrLf

      Case typeCode.Double
         outputBlock.Text += String.Format("Double: {0}", testObject) & vbCrLf

      Case Else
         outputBlock.Text += String.Format("{0}: {1}", typeCode.ToString(), testObject) & vbCrLf
   End Select
End Sub
static void WriteObjectInfo(System.Windows.Controls.TextBlock outputBlock, object testObject)
{
   TypeCode typeCode = Type.GetTypeCode(testObject.GetType());

   switch (typeCode)
   {
      case TypeCode.Boolean:
         outputBlock.Text += String.Format("Boolean: {0}", testObject) + "\n";
         break;

      case TypeCode.Double:
         outputBlock.Text += String.Format("Double: {0}", testObject) + "\n";
         break;

      default:
         outputBlock.Text += String.Format("{0}: {1}", typeCode.ToString(), testObject) + "\n";
         break;
   }
}

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

See Also

Reference