值类型 | 类别 |
---|---|
布尔型 |
|
无符号、数值、整数 |
|
无符号、数值、整数 |
|
数值、十进制 |
|
数值、浮点 |
|
枚举 |
|
数值、浮点 |
|
有符号、数值、整数 |
|
有符号、数值、整数 |
|
有符号、数值、整数 |
|
有符号、数值、整数 |
|
用户定义的结构 |
|
无符号、数值、整数 |
|
无符号、数值、整数 |
|
无符号、数值、整数 |
整型表
类型 | 范围 | 大小 |
---|---|---|
-128 到 127 |
有符号 8 位整数 |
|
0 到 255 |
无符号 8 位整数 |
|
U+0000 到 U+ffff |
16 位 Unicode 字符 |
|
-32,768 到 32,767 |
有符号 16 位整数 |
|
0 到 65,535 |
无符号 16 位整数 |
|
-2,147,483,648 到 2,147,483,647 |
有符号 32 位整数 |
|
0 到 4,294,967,295 |
无符号 32 位整数 |
|
-9,223,372,036,854,775,808 到 9,223,372,036,854,775,807 |
有符号 64 位整数 |
|
0 到 18,446,744,073,709,551,615 |
无符号 64 位整数 |
浮点型表
类型 | 大致范围 | 精度 |
---|---|---|
±1.5e−45 到 ±3.4e38 |
7 位 |
|
±5.0e−324 到 ±1.7e308 |
15 到 16 位 |
内置类型表
C# 类型 | .NET Framework 类型 |
---|---|
System.Boolean |
|
System.Byte |
|
System.SByte |
|
System.Char |
|
System.Decimal |
|
System.Double |
|
System.Single |
|
System.Int32 |
|
System.UInt32 |
|
System.Int64 |
|
System.UInt64 |
|
System.Object |
|
System.Int16 |
|
System.UInt16 |
|
System.String |
备注
除了 object 和 string 外,表中的所有类型均称为简单类型。
默认值表
值类型 | 默认值 |
---|---|
false |
|
0 |
|
'"0' |
|
0.0M |
|
0.0D |
|
表达式 (E)0 产生的值,其中 E 为 enum 标识符。 |
|
0.0F |
|
0 |
|
0L |
|
0 |
|
0 |
|
将所有的值类型字段设置为默认值并将所有的引用类型字段设置为 null 时产生的值。 |
|
0 |
|
0 |
|
0 |
隐式数值转换表
从 | 到 |
---|---|
short、int、long、float、double 或 decimal |
|
short、ushort、int、uint、long、ulong、float、double 或 decimal |
|
int、long、float、double 或 decimal |
|
int、uint、long、ulong、float、double 或 decimal |
|
long、float、double 或 decimal |
|
long、ulong、float、double 或 decimal |
|
float、double 或 decimal |
|
ushort、int、 uint、 long、ulong、 float、double 或 decimal |
|
double |
|
float、 double 或 decimal |
从 int、uint 或 long 到 float 的转换以及从 long 到 double 的转换的精度可能会降低,但数值大小不受影响。
不存在到 char 类型的隐式转换。
不存在浮点型与 decimal 类型之间的隐式转换。
int 类型的常数表达式可转换为 sbyte、byte、short、ushort、uint 或 ulong,前提是常数表达式的值处于目标类型的范围之内。
显式数值转换表
从 | 到 |
---|---|
byte、ushort、uint、ulong 或 char |
|
Sbyte 或者 char |
|
sbyte、 byte、 ushort、 uint、 ulong 或 char |
|
sbyte、 byte、 short 或 char |
|
sbyte、 byte、 short、 ushort、 uint、 ulong 或 decimal |
|
sbyte、 byte、 short、 ushort、 int、 uint、 long、 ulong、 char、 float 或 double |