TypeCode TypeCode TypeCode TypeCode Enum

定義

指定物件的型別。Specifies the type of an object.

public enum class TypeCode
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public enum TypeCode
type TypeCode = 
Public Enum TypeCode
繼承
屬性

欄位

Boolean Boolean Boolean Boolean 3

表示 truefalse 的布林值的簡單型別。A simple type representing Boolean values of true or false.

Byte Byte Byte Byte 6

表示不帶正負號的 8 位元整數的整數型別,其值介於 0 和 255 之間。An integral type representing unsigned 8-bit integers with values between 0 and 255.

Char Char Char Char 4

表示不帶正負號的 16 位元整數的整數型別,其值介於 0 和 65535 之間。An integral type representing unsigned 16-bit integers with values between 0 and 65535. Char 型別的可能值集合對應於 Unicode 字元集。The set of possible values for the Char type corresponds to the Unicode character set.

DateTime DateTime DateTime DateTime 16

表示日期和時間值的型別。A type representing a date and time value.

DBNull DBNull DBNull DBNull 2

資料庫 Null (資料行) 數值。A database null (column) value.

Decimal Decimal Decimal Decimal 15

簡單型別,表示具有 28-29 個有效位數、範圍從 1.0 x 10 -28 到大約 7.9 x 10 28 的數值。A simple type representing values ranging from 1.0 x 10 -28 to approximately 7.9 x 10 28 with 28-29 significant digits.

Double Double Double Double 14

浮點型別,表示具有 15-16 位數精確度、範圍從 5.0 x 10 -324 到大約 1.7 x 10 308 的數值。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.

Empty Empty Empty Empty 0

null 參考。A null reference.

Int16 Int16 Int16 Int16 7

表示帶正負號的 16 位元整數的整數型別,其值介於 -32768 和 32767 之間。An integral type representing signed 16-bit integers with values between -32768 and 32767.

Int32 Int32 Int32 Int32 9

表示帶正負號的 32 位元整數的整數型別,其值介於 -2147483648 和 2147483647 之間。An integral type representing signed 32-bit integers with values between -2147483648 and 2147483647.

Int64 Int64 Int64 Int64 11

表示帶正負號的 64 位元整數的整數型別,其值介於 -9223372036854775808 和 9223372036854775807 之間。An integral type representing signed 64-bit integers with values between -9223372036854775808 and 9223372036854775807.

Object Object Object Object 1

一般型別,表示未由另一個 TypeCode 明確表示的任何參考或實值型別 (Value Type)。A general type representing any reference or value type not explicitly represented by another TypeCode.

SByte SByte SByte SByte 5

表示帶正負號的 8 位元整數的整數型別,其值介於 -128 和 127 之間。An integral type representing signed 8-bit integers with values between -128 and 127.

Single Single Single Single 13

浮點型別,表示具有 7 位數精確度、範圍從 1.5 x 10 -45 到大約 3.4 x 10 38 的數值。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.

String String String String 18

表示 Unicode 字元字串的密封類別型別。A sealed class type representing Unicode character strings.

UInt16 UInt16 UInt16 UInt16 8

表示不帶正負號的 16 位元整數的整數型別,其值介於 0 和 65535 之間。An integral type representing unsigned 16-bit integers with values between 0 and 65535.

UInt32 UInt32 UInt32 UInt32 10

表示不帶正負號的 32 位元整數的整數型別,其值介於 0 和 4294967295 之間。An integral type representing unsigned 32-bit integers with values between 0 and 4294967295.

UInt64 UInt64 UInt64 UInt64 12

表示不帶正負號的 64 位元整數的整數型別,其值介於 0 和 18446744073709551615 之間。An integral type representing unsigned 64-bit integers with values between 0 and 18446744073709551615.

範例

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

備註

在執行介面的類別上呼叫方法,以取得該類別之實例的類型程式碼。GetTypeCode IConvertibleCall the GetTypeCode method on classes that implement the IConvertible interface to obtain the type code for an instance of that class.

否則, 請呼叫物件的GetType方法來取得其Type Type物件, 然後呼叫物件的GetTypeCode方法來取得物件的型別程式碼。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.

適用於