C# 데이터 자료형

C# 데이터 자료형

현재 진행 중인 프로젝트안에서 Byte 단위로 데이터를 핸들링하는 작업을 하다보니 자료형의 크기와 범위가 정확히 기억이 나지않아 계산에 어려움이 있었다.
다시한번 자료형의 크기를 정리하며 상기하는 시간을 가져보자.

C# 및 .NET 타입별 메모리의 크기와 표현 범위.

※ 1 Byte = 8 Bit

- 고정소수점

자료형
형식
크기(byte)
범위
byte System.byte
1
0 ~ 255
Byte System.Byte
1
0 ~ 255
sbyte System.sbyte
1
-128 ~ 127
sByte System.sByte
1
-128 ~ 127
short System.Int16
2
–32,768 ~ 32,767
Int16 System.Int16
2
–32,768 ~ 32,767
ushort System.UInt16
2
0 ~ 65,535
UInt16 System.UInt16
2
0 ~ 65,535
Int System.Int32
4
–2,147,483,648 ~ 2,147,483,647
Int32 System.Int32
4
–2,147,483,648 ~ 2,147,483,647
uint System.UInt32
4
0 ~ 4,294,967,295
UInt32 System.UInt32
4
0 ~ 4,294,967,295
long System.Int64
8
–9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807
Int64 System.Int64
8
–9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807
ulong System.UInt64
8
0 ~ 18,446,744,073,709,551,615
UInt64 System.UInt64
8
0 ~ 18,446,744,073,709,551,615

- 부동소수점

자료형
형식
크기(byte)
범위
float System.Single
4
1.5E-45 ~ 3.4E+38(7자리 유효)
Single System.Single
4
1.5E-45 ~ 3.4E+38(7자리 유효)
double System.Double
8
5.0E-324 ~ 1.7E+308(15자리 유효)
Double System.Double
8
5.0E-324 ~ 1.7E+308(15자리 유효)
decimal System.Decimal
16
7.9E-28 ~ 7.9E+28(28자리 유효)
Decimal System.Decimal
16
7.9E-28 ~ 7.9E+28(28자리 유효)

- 문자 및 문자열

자료형
형식
크기(byte)
범위
char System.Char
2 or 4
UTF-16
Char System.Char
2 or 4
UTF-16
string System.String
_
UTF-16
String System.String
_
UTF-16

Comments

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×