IT공부/IT서적

[시작하세요! C#10 프로그래밍] 3장. C# 기초

shine94 2025. 4. 10. 17:45

* 해당 글은 시작하세요! C#10 프로그래밍 도서를 읽고 정리한 글입니다.

   https://product.kyobobook.co.kr/detail/S000200047759

 

시작하세요! C# 10 프로그래밍 | 정성태 - 교보문고

시작하세요! C# 10 프로그래밍 | 이 책의 목표는 여러분이 C#을 이용해 프로그래밍 기초를 탄탄하게 다질 수 있게 하는 것이다. 이를 위해 C# 언어의 최신 버전인 C# 10의 문법까지 구체적인 예제와

product.kyobobook.co.kr

 

 

 

 

* 정수형 기본타입

   sbyte - System.Sbyte

   byte - System.Byte

   short - System.Int16

   ushort - System.UInt16

   int - System.Int32

   uint - System.UInt32

   long - System.Int64

   ulong - System.UInt64

 

* 실수형 기본타입

   float - System.Single - 4 바이트

   double - System.Double - 8 바이트

   decimal - System.Decimal - 16 바이트

 

* 문자형 기본타입

   char - System.Char → 유니코드 16비트 문자

   string - System.String → 유니코드 문자열

 

   char는 진짜 기본형(primitive type)

   string은 객체(Object)지만, C#에서는 기본형처럼 동작하게 특별 취급됨

 

* 불린형 기본타입

   bool - System.Boolean

 

* 리터럴(literal)

  코드에 직접 쓰인 고정된 값

 

* 상수

   이름이 붙은 변경 불가 변수

 

* C++ 객체 vs C# 참조 형식

  C++ 객체 C# 참조 형식
저장 위치 스택 or 힙 (개발자가 선택 가능) 힙 (참조 변수는 스택에 저장)
기본 복사 동작 복사 생성자 호출 참조 복사(같은 객체를 가리킴)
메모리 해제 수동 (delete) or 스마트 포인터 사용 자동 (GC에 의해 수거)

 


 

  .method private hidebysig static void
    Main(
      string[] args
    ) cil managed
  {
    .entrypoint
    .custom instance void [System.Runtime]System.Runtime.CompilerServices.NullableContextAttribute::.ctor(unsigned int8)
      = (01 00 01 00 00 ) // .....
      // unsigned int8(1) // 0x01
    .maxstack 2
    .locals init (
      [0] int32 n1,
      [1] int32 n2,
      [2] int64 sum
    )

    // [6 5 - 6 6]
    IL_0000: nop

    // [7 9 - 7 21]
    IL_0001: ldc.i4.s     50 // 0x32
    IL_0003: stloc.0      // n1

    // [9 9 - 9 18]
    IL_0004: ldc.i4.s     100 // 0x64
    IL_0006: stloc.1      // n2

    // [11 9 - 11 28]
    IL_0007: ldloc.0      // n1
    IL_0008: ldloc.1      // n2
    IL_0009: add
    IL_000a: conv.i8
    IL_000b: stloc.2      // sum

    // [13 9 - 13 32]
    IL_000c: ldloc.2      // sum
    IL_000d: call         void [System.Console]System.Console::WriteLine(int64)
    IL_0012: nop

    // [14 5 - 14 6]
    IL_0013: ret

  } // end of method Program::Main