值类型表

值类型 类别

bool

布尔型

byte

无符号、数值、整数

char

无符号、数值、整数

decimal

数值、十进制

double

数值、浮点

enum

枚举

float

数值、浮点

int

有符号、数值、整数

long

有符号、数值、整数

sbyte

有符号、数值、整数

short

有符号、数值、整数

struct

用户定义的结构

uint

无符号、数值、整数

ulong

无符号、数值、整数

ushort

无符号、数值、整数



整型表

类型 范围 大小

sbyte

-128 到 127

有符号 8 位整数

byte

0 到 255

无符号 8 位整数

char

U+0000 到 U+ffff

16 位 Unicode 字符

short

-32,768 到 32,767

有符号 16 位整数

ushort

0 到 65,535

无符号 16 位整数

int

-2,147,483,648 到 2,147,483,647

有符号 32 位整数

uint

0 到 4,294,967,295

无符号 32 位整数

long

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

有符号 64 位整数

ulong

0 到 18,446,744,073,709,551,615

无符号 64 位整数



浮点型表

类型 大致范围 精度

float

±1.5e−45 到 ±3.4e38

7 位

double

±5.0e−324 到 ±1.7e308

15 到 16 位



内置类型表

C# 类型 .NET Framework 类型

bool

System.Boolean

byte

System.Byte

sbyte

System.SByte

char

System.Char

decimal

System.Decimal

double

System.Double

float

System.Single

int

System.Int32

uint

System.UInt32

long

System.Int64

ulong

System.UInt64

object

System.Object

short

System.Int16

ushort

System.UInt16

string

System.String


    备注
       除了 object 和 string 外,表中的所有类型均称为简单类型。

默认值表

值类型 默认值

bool

false

byte

0

char

'"0'

decimal

0.0M

double

0.0D

enum

表达式 (E)0 产生的值,其中 E 为 enum 标识符。

float

0.0F

int

0

long

0L

sbyte

0

short

0

struct

将所有的值类型字段设置为默认值并将所有的引用类型字段设置为 null 时产生的值。

uint

0

ulong

0

ushort

0



隐式数值转换表


从 到

sbyte

short、int、long、float、double 或 decimal

byte

short、ushort、int、uint、long、ulong、float、double 或 decimal

short

int、long、float、double 或 decimal

ushort

int、uint、long、ulong、float、double 或 decimal

int

long、float、double 或 decimal

uint

long、ulong、float、double 或 decimal

long

float、double 或 decimal

char

ushort、int、 uint、 long、ulong、 float、double 或 decimal

float

double

ulong

float、 double 或 decimal

  备注
     从 int、uint 或 long 到 float 的转换以及从 long 到 double 的转换的精度可能会降低,但数值大小不受影响。
     不存在到 char 类型的隐式转换。
     不存在浮点型与 decimal 类型之间的隐式转换。
     int 类型的常数表达式可转换为 sbyte、byte、short、ushort、uint 或 ulong,前提是常数表达式的值处于目标类型的范围之内。

显式数值转换表

从 到

sbyte

byte、ushort、uint、ulong 或 char

byte

Sbyte 或者 char

short

sbyte、 byte、 ushort、 uint、 ulong 或 char

ushort

sbyte、 byte、 short 或 char

int

sbyte、 byte、 short、 ushort、 uint、 ulong 或 decimal

decimal

sbyte、 byte、 short、 ushort、 int、 uint、 long、 ulong、 char、 float 或 double



相关文章:

  • 2021-11-11
  • 2021-11-01
  • 2021-07-29
  • 2022-02-19
  • 2022-12-23
  • 2022-01-12
  • 2021-08-08
猜你喜欢
  • 2021-12-13
  • 2021-11-21
  • 2021-12-04
  • 2021-12-17
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案