TypeCode 枚举

定义

指定对象的类型。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
继承
TypeCode
属性

字段

Boolean 3

简单类型,表示 truefalse 的布尔值。A simple type representing Boolean values of true or false.

Byte 6

整型,表示值介于 0 到 255 之间的无符号 8 位整数。An integral type representing unsigned 8-bit integers with values between 0 and 255.

Char 4

整型,表示值介于 0 到 65535 之间的 16 位无符号整数。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 16

表示一个日期和时间值的类型。A type representing a date and time value.

DBNull 2

数据库空(列)值。A database null (column) value.

Decimal 15

简单类型,表示从 1.0 x 10 -28 到大约 7.9 x 10 28 且有效位数为 28 到 29 位的值。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 14

浮点型,表示从大约 5.0 x 10 -324 到 1.7 x 10 308 且精度为 15 到 16 位的值。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 0

一个空引用。A null reference.

Int16 7

整型,表示值介于 -32768 到 32767 之间的有符号 16 位整数。An integral type representing signed 16-bit integers with values between -32768 and 32767.

Int32 9

整型,表示值介于 -2147483648 到 2147483647 之间的 32 位有符号整数。An integral type representing signed 32-bit integers with values between -2147483648 and 2147483647.

Int64 11

整型,表示值介于-9223372036854775808 和 9223372036854775807 之间的 64 位有符号整数。An integral type representing signed 64-bit integers with values between -9223372036854775808 and 9223372036854775807.

Object 1

常规类型,表示不会由另一个 TypeCode 显式表示的任何引用或值类型。A general type representing any reference or value type not explicitly represented by another TypeCode.

SByte 5

整型,表示值介于 -128 到 127 之间的 8 位有符号整数。An integral type representing signed 8-bit integers with values between -128 and 127.

Single 13

浮点型,表示从大约 1.5 x 10 -45 到 3.4 x 10 38 且精度为 7 位的值。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 18

密封类类型,表示 Unicode 字符串。A sealed class type representing Unicode character strings.

UInt16 8

整型,表示值介于 0 到 65535 之间的 16 位无符号整数。An integral type representing unsigned 16-bit integers with values between 0 and 65535.

UInt32 10

整型,表示值介于 0 到 4294967295 之间的 32 位无符号整数。An integral type representing unsigned 32-bit integers with values between 0 and 4294967295.

UInt64 12

整型,表示值介于 0 到 18446744073709551615 之间的 64 位无符号整数。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.

适用于