内置类型表(C# 参考)Built-in types table (C# Reference)

下表显示内置 C# 类型的关键字,即 System 命名空间中预定义类型的别名。The following table shows the keywords for built-in C# types, which are aliases of predefined types in the System namespace.

C# 类型C# type .NET 类型.NET type
boolbool System.Boolean
bytebyte System.Byte
sbytesbyte System.SByte
charchar System.Char
decimaldecimal System.Decimal
doubledouble System.Double
floatfloat System.Single
intint System.Int32
uintuint System.UInt32
longlong System.Int64
ulongulong System.UInt64
objectobject System.Object
shortshort System.Int16
ushortushort System.UInt16
stringstring System.String

备注Remarks

此表中的所有类型,除 objectstring 外,皆被称为简单类型。All of the types in the table, except object and string, are referred to as simple types.

.NET 类型及其 C# 类型关键字别名可互换。The .NET types and their C# type keyword aliases are interchangeable. 例如,可通过使用以下任意一个声明来声明整型变量:For example, you can declare an integer variable by using either of the following declarations:

int x = 123;
System.Int32 y = 123;

使用 typeof 运算符以获取表示指定类型的 System.Type 实例:Use the typeof operator to get the System.Type instance that represents the specified type:

Type stringType = typeof(string);
Console.WriteLine(stringType.FullName);

Type doubleType = typeof(System.Double);
Console.WriteLine(doubleType.FullName);

// Output:
// System.String
// System.Double

请参阅See also