Type.GetTypeCode(Type) Type.GetTypeCode(Type) Type.GetTypeCode(Type) Method

定義

取得指定的 Type 的基礎類型程式碼。Gets the underlying type code of the specified Type.

public:
 static TypeCode GetTypeCode(Type ^ type);
public static TypeCode GetTypeCode (Type type);
static member GetTypeCode : Type -> TypeCode

參數

type
Type Type Type

要取得其基礎類型程式碼的類型。The type whose underlying type code to get.

傳回

基礎類型程式碼,如果 Emptytype 則為 nullThe code of the underlying type, or Empty if type is null.

範例

下列程式碼範例示範如何TypeCode列舉型別可用。The following code example demonstrates how the TypeCode enumeration can be used. 在決策區塊WriteObjectInfo方法中,TypeCodeObject會檢查參數,並適當的訊息寫入至主控台。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.

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, testObject );
         break;
   }
}
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;
    }
}
Sub WriteObjectInfo(ByVal testObject As Object)
    Dim typeCode As TypeCode = Type.GetTypeCode(testObject.GetType())

    Select Case typeCode
        Case typeCode.Boolean
            Console.WriteLine("Boolean: {0}", testObject)

        Case typeCode.Double
            Console.WriteLine("Double: {0}", testObject)

        Case Else
            Console.WriteLine("{0}: {1}", typeCode.ToString(), testObject)
    End Select
End Sub

備註

當您繼承自Type,您可以藉由覆寫來變更此方法的行為GetTypeCodeImpl方法。When you inherit from Type, you can change the behavior of this method by overriding the GetTypeCodeImpl method.

適用於

另請參閱