用 | C++ | 大小 | C# | 大小 | .NET Framework类型 | 取值范围 | 后缀 |
字符 | char | 1 | sbyte | 1 | System.SByte | -128~127 | |
字符(无符号) | unsigned char | 1 | byte | 1 | System.Byte | 0~255 | |
宽字符 | wchar_t | 2 | char | 2 | System.Char | ||
宽字符(无符号) | unsigned wchar_t | 2 | |||||
逻辑值 | bool | 1 | bool | 1 | System.Boolean | true,false | |
短整数 | short | 2 | short | 2 | System.Int16 |
-32,768 .. 32,767 |
|
短整数(无符号) | unsigned short | 2 | ushort | 2 | System.UInt16 | 0~65535(2的16次方) | |
整数 | int | 4 | int | 4 | System.Int32 |
-2,147,483,648 .. 2,147,483,647 |
|
整数(无符号) | unsigned int | 4 | uint | 4 | System.UInt32 |
0 .. 4,294,967,295 |
|
长整型 | long | 8 | long | 8 | System.Int64 |
-9,223,372,036,854,775,808 .. 9,223,372,036,854,775,807 |
L (最好用大写,因为小写l容易与1混淆) |
长整型(无符号) | unsigned long | 8 | ulong | 8 | System.UInt64 |
0 .. 18,446,744,073,709,551,615 |
|
单精度实数 | float | 4 | float | 4 | System.Single |
-3.402823e38 .. 3.402823e38 |
|
双精度实数 | double | 8 | double | 8 | System.Double |
-1.79769313486232e308 .. 1.79769313486232e308 |
d |
长双精度实数 | long double | 10 | decimal | 16 | System.Decimal |
-79228162514264337593543950335 .. 79228162514264337593543950335 |
m |
字符串 | string | string | System.String | ||||
对象 | object | System.Object |
定义类型别名
C++中,使用typedef关键字 : typedef short Age;
C#中,使用using关键字 : using Age = System.Int16;
责任编辑:cyth