using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 값형식과참조형식
{
    class Program
    {
        static void Main(string[] args)
        {
            // 값 형식 : Value Type : 닷넷이 관리하는 메모리의 스택에 보관
            int i = 1234;

            // 참조 형식 : Reference Type : 닷넷의 힙 메모리에 보관
            string s = "안녕\0하세요"; // 리터럴(Literal)
            Console.WriteLine("{0}", s); // "안녕"만 출력된다.

            // 박싱(Boxing)과 언박싱(UnBoxing)
            string su = "1234";
            int num = Convert.ToInt32(su); // 힙 -> 스택 : 언박싱
            su = i.ToString(); // 스택 -> 힙 : Boxing
            su = null; // GC엔진활동

            // 구조체는 값형식, 클래스는 참조형식
            // Car car = new Car(); // 생성
            // car.Run(); // 사용
            // delete car; // 이런 명령어 없다...
        }
    }
}


/*
박싱과 언박싱은 최소로 하는게 좋다.(= 되도록 하지 않는게 좋다.)
속도가 늦어지기 때문이다.
 
\0  =>  종결문자열을 나타낸다.(= 문자열의 끝) 원칙적으로 \0이후의 문자열은 출력되지 않는다.
*/

Posted by holland14
: