Lire en anglais Modifier

Partager via


TypeCode Enum

Definition

Specifies the type of an object.

public enum TypeCode
[System.Serializable]
public enum TypeCode
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum TypeCode
Inheritance
TypeCode
Attributes

Fields

Name Value Description
Empty 0

A null reference.

Object 1

A general type representing any reference or value type not explicitly represented by another TypeCode.

DBNull 2

A database null (column) value.

Boolean 3

A simple type representing Boolean values of true or false.

Char 4

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.

SByte 5

An integral type representing signed 8-bit integers with values between -128 and 127.

Byte 6

An integral type representing unsigned 8-bit integers with values between 0 and 255.

Int16 7

An integral type representing signed 16-bit integers with values between -32768 and 32767.

UInt16 8

An integral type representing unsigned 16-bit integers with values between 0 and 65535.

Int32 9

An integral type representing signed 32-bit integers with values between -2147483648 and 2147483647.

UInt32 10

An integral type representing unsigned 32-bit integers with values between 0 and 4294967295.

Int64 11

An integral type representing signed 64-bit integers with values between -9223372036854775808 and 9223372036854775807.

UInt64 12

An integral type representing unsigned 64-bit integers with values between 0 and 18446744073709551615.

Single 13

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.

Double 14

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.

Decimal 15

A simple type representing values ranging from 1.0 x 10 -28 to approximately 7.9 x 10 28 with 28-29 significant digits.

DateTime 16

A type representing a date and time value.

String 18

A sealed class type representing Unicode character strings.

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.

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;
    }
}

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.

Applies to

Produit Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0