🌸 숫자 데이터 형식
- 원하는 자리에 자릿수 구분자 _ 를 사용할 수 있다.
using System;
namespace IntegralTypes
{
class MainApp
{
static void Main(string[] args)
{
int a = -1000_0000;
uint b = 3_0000_0000;
Console.WriteLine($"a={a}, b={b}");
}
}
}
[실행 결과]
a=-10000000, b=300000000
✔️ 2진수, 10진수, 16진수
using System;
namespace IntegralTypes
{
class MainApp
{
static void Main(string[] args)
{
byte a = 240;
byte b = 0b1111_0000;
byte c = 0XF0;
uint d = 0x1234_abcd;
Console.WriteLine($"10진수 a={a}, 2진수 b={b}");
Console.WriteLine($"16진수 c={c}, d={d}");
}
}
}
[실행 결과]
10진수 a=240, 2진수 b=240
16진수 c=240, d=305441741
✔️ 실수 형식
| 데이터 형식 | 접미사 |
|---|
| float | f |
| double | 없음 |
| decimal | m |
using System;
namespace IntegralTypes
{
class MainApp
{
static void Main(string[] args)
{
float a = 3.1415_9265_3589_7932_3846_2643_3832_79f;
double b = 3.1415_9265_3589_7932_3846_2643_3832_79;
decimal c = 3.1415_9265_3589_7932_3846_2643_3832_79m;
Console.WriteLine($"a={a}\nb={b}\nc={c}");
}
}
}
[실행 결과]
a=3.1415927
b=3.141592653589793
c=3.1415926535897932384626433833
🌸 문자, 문자열 형식
- char: 개별 문자, 작은 따옴표 ' '
- string: 문자열, 큰 따옴표 " "
using System;
namespace IntegralTypes
{
class MainApp
{
static void Main(string[] args)
{
char a = 'H';
char b = 'e';
char c = 'l';
char d = 'l';
char e = 'o';
string f = " World!";
Console.Write(a);
Console.Write(b);
Console.Write(c);
Console.Write(d);
Console.Write(e);
Console.Write(f);
}
}
}
[실행 결과]
Hello World!