커뮤니티
WSC Info.
제목:    데이터, 연산자, 제어문 요약
  3131   김윤중

데이터

  • 기본데이터형식-복합데이터형식
  • 값형식-참조형식
  • 기본데이터형식
    •  
      Type
      Represents Range Default Value example
      정수형 byte 8-bit unsigned integer 0 to 255 0 byte=255;
      sbyte 8-bit signed integer type -128 to 127 0 sbyte s=-128;
      short 16-bit signed integer type -32,768 to 32,767 0 short s=-32768;
      ushort 16-bit unsigned integer type 0 to 65,535 0 ushort=65535;
      int 32-bit signed integer type -2,147,483,648 to 2,147,483,647 0 int i=-2147483,648;
      uint
      32-bit unsigned integer type
      0 to 4,294,967,295
      0 uint u=4294967295;
      long 64-bit signed integer type -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 0L long l=-9223372036854775808;
      ulong 64-bit unsigned integer type 0 to 18,446,744,073,709,551,615 0 ulong u=10;
      실수형 float 32-bit single-precision floating point type -3.4 x 1038 to + 3.4 x 1038 0.0F 1.0d/3:0.3333333 (7digits)
      double 64-bit double-precision floating point type (+/-)5.0 x 10-324 to (+/-)1.7 x 10308 0.0D 1.0/3:0.333~3(15~16digits)
      decimal 128-bit precise decimal values with 28-29 significant digits (-7.9 x 1028 to 7.9 x 1028) / 100 to 28 0.0M 1m/3:0.333~3 (28~29digits)
      문자형 char 16-bit Unicode character U +0000 to U +ffff '\0' char c='a', d='국'; 
      불린형 bool Boolean value True or False FALSE  
                 
  • 형변환
    • 암시적 형변환 byte b=250; short s=b;  //250
    • 명시적형변환  ushort=40000; short s=(short)n; //-25536
  • 상수형
    • const int a=0;
    • const int b=1;
    • const doible b=10;
  • 열거형
    • enum DialogResult {Yes,No,Cancel=4, OK}
    • DialogResult dm=DialogResult.Yes;  
    • (int)DialogResult.Yes : 0        (int)DialogResult.No : 1 (int)DialogResult.Cencel : 4    (int)DialogResult.OK : 5
    • (string)DialogResult.Yes  => "Yes"
  • nullable 형
    • int? length = customers?.Length; // null if customers is null
      Customer first = customers?[0];  // null if customers is null
      int? count = customers?[0]?.Orders?.Count();  // null if customers, the first customer, or Orders is null
      • int[] cs=null;
        int? len=cs.Length; //Error
        int? len=cs?.Length; //null 저장
      • int[] cs=new int[2];
        int? len=cs.Length; //2
        int? len=cs?.Length; //2 저장
  • var 형
    • var a=3;       //컴파일러 자동 형 지정방식
      var b="Hello";

연산자

  • 분류  연산자 
    산술 연산자  +, -, *, /, % 
    증가/감소 연산자  ++, -- 
    관계 연산자   <, >, ==, !=, <=, >= 
    조건 연산자  ?: 
    논리 연산자  &&, ||, ! 
    비트 연산자  <<, >>, &, |, ^, ~ 
    할당 연산자  =, +=, -=, *=, /=, %=, &=, |=, ^=, <<=, >>= 

제어문

  • If - else 문
  • switch(number)

        case 1 :  Console.WriteLIne(1); break;
        case 2 :  Console.WriteLIne(1); break;
       default  :  ;       
    }
  • int sum = 0; int i = 0; 
    while (i <= 10) {
          sum += i++;
     } 
  • int sum = 0; int i = 0; 
    do  {
             sum += i++;
     } while (i <= 10);
     Console.WriteLine(sum);
  • int  sum = 0;
     for (int i = 0; i <= 10; i++)   {
            sum += i;
       }
      Console.WriteLine(sum); 
  •  sum = i=0;
      Loop: sum += i;
             i++;
      if (i <= 10)
             goto Loop;
      Console.WriteLine(sum);
  • int[] arr=new int[]{10,20)
    foreach(int n in arr)
        Console.writeLine(n); 
  • break, continue 