ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • C# 자료형 정리
    Programming/C# 2020. 2. 17. 14:15
    자료형 범위 설명
    sbyte -128 ~ 127

    부호가 존재하는 8 bit 정수

    부호가 있다

    아주 작은 값들을 보관하는 용도로 쓰임

    byte 0~255 부호가 없는 8 bit
    short -32,768~32,767  
    ushort 0~ 65535  
    int -2147483648~2147483647  
    uint 0~4294967295  
    long -9223372036854775808~9223372036854775808 엄청나다
    ulong 0~18446744073709551615 더 엄청나다
    float +-1.5e-45 ~ +-3.4e38 엄청난데 소수점(실수)자리 값까지 담을 수 있다.

     

    double +-5.0e-324~+-1.7e308

    크기가 float보다 더 대단하다.

    물론 실수값도 담을 수 있다.

    decimal +-1.0*10-^28 +- 7.9 * 10^28 16 byte , 크기가 ㄹㅇ 엄청나다.
    char U+0000~U+fff 문자를 담을 수 있다.
    string   문자열 가능
    bool   참(true) 또는 거짓(false)

     

    자료형별 크기

    sizeof(type)함수를 통해서 크기를 얻을 수 있다.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConsoleApp9
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("sbyte = {0} bytes", sizeof(sbyte));
                Console.WriteLine("byte = {0} bytes", sizeof(byte));
                Console.WriteLine("short = {0} bytes", sizeof(short));
                Console.WriteLine("sbyte = {0} bytes", sizeof(sbyte));
                Console.WriteLine("ushort = {0} bytes", sizeof(ushort));
                Console.WriteLine("int = {0} bytes", sizeof(int));
                Console.WriteLine("uint = {0} bytes", sizeof(uint));
                Console.WriteLine("long = {0} bytes", sizeof(long));
                Console.WriteLine("ulong = {0} bytes", sizeof(ulong));
                Console.WriteLine("float = {0} bytes", sizeof(float));
                Console.WriteLine("double = {0} bytes", sizeof(double));
                Console.WriteLine("decimal = {0} bytes", sizeof(decimal));
                Console.WriteLine("char = {0} bytes", sizeof(char));
                Console.WriteLine("bool = {0} bytes", sizeof(bool));
    
                Console.Read();
    
            }
        }
    }
    

     

Designed by Tistory.