[C#] 데이터 타입
C# 데이터 타입 |
설명 |
.NET 데이터 타입 |
int |
32비트 integer |
System.int32 |
uint |
32비트 정수형 integer |
System.UInt32 |
double |
64비트 부동소수점 |
System.Double |
decimal |
128비트 Decimal |
System.Decimal |
char |
16비트 유니코드 문자 |
System.Char |
string |
유니코드 문자열 |
System.String |
Object |
모든 타입의 기본 클래스 유형 포함 |
System.Object |
long |
64비트 integer |
System.Int64 |
ulong |
64비트 정수형 integer |
System.UInt64 |
short |
16비트 integer |
System.Int16 |
ushort |
16비트 정수형 integer |
System.UInt16 |
byte |
8비트 integer |
System.Byte |
sbyte |
8비트 integer |
System.SByte |
bool |
True or False |
System.Boolean |
C# Literal Type : C# 코드에서 123, true, "ABC"와 같이 값을 직접 써줄 수 있음. C#에서 리터럴 데이터를 사용할 때, 접미어 표시(Suffix)가 따로 없는 경우 C# 컴파일러는 데이터 타입에 기본적으로 그 값을 할당함.
특정 데이터 타입을 지정하고 싶으면, 리터럴 데이타 뒤에 1~2자의 타입 지정 접미어(Suffix)를 추가해야 함.
C# 데이터 타입(literal) |
접미어(Suffix) |
Example |
long |
L |
314L |
uint |
U |
314U |
ulong |
UL |
314UL |
float |
F |
3.14F |
double |
D |
3.14D |
Decimal |
M |
3.14M |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
bool b = true; /*Bool*/ /*숫자*/ short sh = -123456; int i = 72; long l = 314L; /*L suffix*/ float f = 3.14F; /*F suffix*/ double d1 = 3.14; double d2 = 3.14D; /*D suffix*/ decimal d = 3.14M; /*M suffix*/
/*문자*/ char c = 'A'; string s = "Hello";
/*DateTime 2019.03.27 17:35*/ DateTime dt = new DateTime(2019, 03, 27, 17, 35, 0); /*Nullable 타입*/ int? i = null; i = 101;
bool? b = null;
/*int? 를 int로*/ Nullable<int> a = null; a = 10; int i = a.Value;
|