c#基本数据类型占用字节数/取值范围/包装类

类型名称 类型说明 字节长度(bytes数) 取值范围 .NET框架类型(包装类) 默认值
sbyte 8位有符号整数 1bytes -128~127 System.SByte 0
byte 8位无符号整数 1bytes 0~255 System.Byte 0
short 16位有符号整数 2bytes -32768~32767 System.Int16 0
ushort 16位无符号整数 2bytes 0~65535 System.UInt16 0
int 32位有符号整数 4bytes -2,147,483,648~2,147,483,647 System.Int32 0
uint 32位无符号整数 4bytes 0~4,294,967,295 System.UInt32 0
long 64位有符号整数 8bytes

-9,223,372,036,854,775,808

~9,223,372,036,854,775,807

System.Int64 0
ulong 64位无符号整数 8bytes 0~18,446,744,073,709,551,615 System.UInt64 0
nint 带符号的32位或64位整数 (在32位进程中是4bytes,在64位进程中是8bytes) 取决于(在运行时计算的)平台 System.IntPtr -
nuint 无符号的32位或64位整数 (在32位进程中是4bytes,在64位进程中是8bytes) 取决于(在运行时计算的)平台 System.UIntPtr -
float 单精度浮点数
(精度为大约6-9位有效小数位)
4bytes 1.5×10 -45 ~3.4×10 38
System.Single 0.0f
double 双精度浮点数
(精度为大约15-17位有效小数位)
8bytes ±5.0×10 -324 ~±1.7×10 308 System.Double 0.0d
decimal 实数类型
(精度为28-29位有效小数位)
16bytes ±1.0×10 28 ~±7.9228×10 28 System.Decimal 0m
bool 布尔值 1bytes(实际仅需1bit) true /false System.Boolean false
char Unicode字符串 U+0000~U+ffff System.Char \x0000
object 所有其他类型的基类,包括简单类型     System.Object  
string 0个或多个Unicode字符所组成的序列     System.String  
dynamic 使用动态类型语言编写的程序集时使用     无相应的.NET类型  
阿里云(新老用户)双11特惠
腾讯云双11特惠活动入口

腾讯云双11拼团特惠入口

恒创-海外免备服务器特惠

华纳-海外免备服务器特惠

云服务新老用户优惠汇总
x