Type.GetTypeCode Method

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

Gets the underlying type code of the specified Type.

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

Syntax

'Declaration
Public Shared Function GetTypeCode ( _
    type As Type _
) As TypeCode
public static TypeCode GetTypeCode(
    Type type
)

Parameters

Return Value

Type: System.TypeCode
The TypeCode value of the underlying type.

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 written to the console.

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