C#内置类型与.Net和SqlServer类型的对应关系表

一、C#内置类型与.Net类型对照关系

.NET 类型

数据

类型

C#

内置类型

占用

字节

示例 或 取值范围

System.Boolean

值类型

bool

1

true --> 1或-1    false --> 0

System.Byte

值类型

byte

1

0 到 255

1 byte(字节) = 8 bit(位)

System.SByte

值类型

sbyte

1

-128 到 127

System.Char

值类型

char

2

字符 -- ‘j’

Unicode转义序列 -- '\u006A'

十六进制转义序列 -- '\x006A'

System.Decimal

值类型

decimal

16

精确浮点数值类型

4.7M

System.Double

值类型

double

8

近似浮点数值类型

3.5 或 3.5D

System.Single

值类型

float

4

近似浮点数值类型

5.4F

System.Int32

值类型

int

4

十进制:42

十六进制:0x2A 

二进制:0b_0010_1010(等同于0b101010)

数字分隔符“_”可用于所有类型数字文本

如:0b_0010_10103_000.5M

System.UInt32

值类型

uint

4

52U

System.IntPtr

值类型

nint

4或8

System.UIntPtr

值类型

nuint

4或8

System.Int64

值类型

long

8

85L

System.UInt64

值类型

ulong

8

52UL

System.Int16

值类型

short

2

-32,768 到 32,767

System.UInt16

值类型

ushort

2

0 到 65,535

System.Object

引用类型

object

不定

System.String

引用类型

string

不定

System.Object

引用类型

dynamic

不定

System.Array

引用类型

[]数组

不定

二、SQL Server 数据类型与C#和.Net的对应

序号

.NET

数据类型

C#内置

数据类型

SQL Server

数据类型

字节数

1

Int64

long

整型数值类型 85L

bigint

2

Byte[]

byte[]

数组是引用类型

byte是值类型

binary

3

Boolean

bool

bit

4

String

Char[]

string

引用类型

char

5

DateTime

date

6

DateTime

datetime

7

DateTime

datetime2

8

DateTimeOffset

datetimeoffset

9

Decimal

decimal

精确浮点数值类型 4.7M

decimal

10

Byte[]

FILESTREAM

varbinary(MAX)

11

Double

double

近似浮点数值类型

3.5 或 3.5D

float

12

Byte[]

byte[]

image

varbinary(MAX)

13

Int32

int

十进制:42

十六进制:0x2A

八进制:0b1010

int

long:57L

uint:52U

ulong:53UL

14

Decimal

decimal

money

15

String

Char[]

string

nchar

16

String

Char[]

string

ntext

nvarchar(MAX)

17

Decimal

numeric

18

String

Char[]

string

nvarchar

19

Single

float

近似浮点数值类型 5.4F

real

20

DateTime

smalldatetime

21

Int16

short

smallint

22

Decimal

smallmoney

23

String

Char[]

string

text

varchar(MAX)

24

TimeSpan

time

25

Byte[]

timestamp

26

Byte

byte

tinyint

27

Byte[]

varbinary

28

String

Char[]

string

varchar

29

cursor

30

Byte[]

rowversion

31

hierarchyid

32

Guid

Guid

uniqueidentifier

33

Object

object

sql_variant

34

Xml

xml

35

table

36

Spatial Geometry

 Types

37

Spatial Geography

 Types

三、SQL Server 对数据类型使用以下优先级顺序

0、用户定义数据类型(最高)

1、sql_variant

2、xml

3、datetimeoffset

4、datetime2

5、datetime

6、smalldatetime

7、date

8、time

9、float

10、real

11、decimal

12、money

13、smallmoney

14、bigint

15、int

16、smallint

17、tinyint

18、bit

19、ntext

20、text

21、图像

22、timestamp

23、uniqueidentifier

24、nvarchar(包括 nvarchar(max))

25、nchar

26、varchar(包括 varchar(max))

27、char

28、varbinary(包括 varbinary(max))

29、binary(最低)

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值