자료형

2016. 12. 11. 22:36C# 콘솔( Console )/변수, 자료형, 형변환

구분

 데이터형식

 Byte

 범위

정수

byte

1

0 ~ 255

정수

sbyte

1

-128 ~ 127

정수

short

2

-32,768 ~ 32,767

정수

ushort

2

0 ~ 65,535

정수

int

4

-2,147,483,648 ~ 2,147,483,647

정수

uint

4

0 ~ 4,294,967,295

정수

long

8

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

정수

ulong

8

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

문자

char

2

 

문자열

Strin


 

실수

float

4

-3.402823E+38 ~ 3.402823E+38

실수

double

8

-1.79769313486232E+308 ~ 1.79769313486232E+308

실수

decimal

16

-79,228,162,514,264,337,593,543,950,335 

~
79,228,162,514,264,337,593,543,950,335

논리

bool

1

true, false

객체

object

 































ex)



          static void Main(string[] args)
        {
            //sbyte : -128 ~ 127
            Console.WriteLine("sbyte : {0}바이트, {1} ~ {2}", sizeof(sbyte), sbyte.MinValue, sbyte.MaxValue);
            //byte(unsigned) : 0 ~ 255
            Console.WriteLine("byte : {0}바이트, {1} ~ {2}", sizeof(byte), byte.MinValue, byte.MaxValue);
            //short : -32,768 ~ 32,767
            Console.WriteLine("short : {0}바이트, {1} ~ {2}", sizeof(short), short.MinValue, short.MaxValue);
            //ushort :0 ~ 65,535
            Console.WriteLine("ushort : {0}바이트, {1} ~ {2}", sizeof(ushort), ushort.MinValue, ushort.MaxValue);
            //int : -2,147,483,648 ~ 2,147,483,647
            Console.WriteLine("int : {0}바이트, {1} ~ {2}", sizeof(int), int.MinValue, int.MaxValue);
            //uint : 0 ~ 4,294,967,295
            Console.WriteLine("uint : {0}바이트, {1} ~ {2}", sizeof(uint), uint.MinValue, uint.MaxValue);
            //long : -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807
            Console.WriteLine("long : {0}바이트, {1} ~ {2}", sizeof(long), long.MinValue, long.MaxValue);
            //ulong : 0 ~ 18,446,744,073,709,551,615
            Console.WriteLine("ulong : {0}바이트, {1} ~ {2}", sizeof(ulong), ulong.MinValue, ulong.MaxValue);
            //char(unicode) : 문자당 2바이트
            Console.WriteLine("char : {0}바이트, {1} ~ {2}", sizeof(char), char.MinValue, char.MaxValue);
            //float : -3.402823E+38 ~ 3.402823E+38
            Console.WriteLine("float : {0}바이트, {1} ~ {2}", sizeof(float), float.MinValue, float.MaxValue);
            //double :-1.79769313486232E+308 ~ 1.79769313486232E+308
            Console.WriteLine("double : {0}바이트, {1} ~ {2}", sizeof(double), double.MinValue, double.MaxValue);
            //decimal :-79,228,162,514,264,337,593,543,950,335 ~ 79,228,162,514,264,337,593,543,950,335
            Console.WriteLine("decimal : {0} 바이트, {1} ~ {2}", sizeof(decimal), decimal.MinValue, decimal.MaxValue);
        }