All posts by kpark

Data Type

Boolean (bool)


Character (char)


Enumeration (enum)


Numeric (int, long, float, double, decimal, etc)


String

Object

Struct

ArrayTest

StructTest

Value Type vs Reference Type

값 형식(Value Type)과 참조 형식(Reference Type)



























구분


값 형식(Value Type)


참조 형식(Reference Type)


종류


내장형 (int, char, float,…)


사용자 정의형 (enum, stuct)


Object, string, class, interface, delegate, ..


메모리 사용


스택


스택,


대입(Assignment)


복사


참조 변경


크기


고정


가변


Garbage Collector 지원


지원 안됨


지원 됨


값형식(Value Type)은 메모리를 직접 가리킨다.
참조형식(Reference Type)은 메모리를 참조를 통해서 가리킨다.

값형식(Value Type)은 변수의 선언과 동시에 메모리에 생성한다.
참조형식(Reference Type)은 변수의 선언과 메모리 생성 분리하여 생성한다.

값형식(Value Type)은 값형식끼리 할당 메모리의 값들을 그대로 복사한다.
참조형식(Reference Type)은 참조형식끼리 할당 할때 참조값만을 복사한다.

http://dis.dankook.ac.kr/lectures/hci10/entry/Value-Type과-Reference-Type의-비교

Stack vs Heap

스택(Stack)은 Last-In, First-Out(LIFO) 방식으로 아이템을 저장하는 메모리의 자료 구조이다.
스택(Stack)은 지역변수(local variable)와 함수 리턴주소를 저장한다. C#에서 값형식(Value Type) 데이터는 스택에 저장된다.

힙(Heap)은 프로그램 코드 영역과는 별도로 유지되는 자유 메모리 공간이다.
힙(Heap)은 C#에서 new를 사용하여 메모리 할당하여 이 공간을 사용할 수 있다.
힙에 할당된 데이터는 전역변수(global variable)처럼 프로그램이 종료될 때까지 유지된다.
C#에서는 더이상 참조하지 않는 데이터를 자동으로 해제해준다 (gabage collection).
C#에서는 참조형식(Reference Type)은 스택에 메모리 주소를 저장하고 힙에 실질적인 데이터가 저장된다.

http://en.csharp-online.net/Stack_vs._Heap

http://stackoverflow.com/questions/79923/what-and-where-are-the-stack-and-heap

Main Method

http://msdn.microsoft.com/ko-kr/library/acy3edy3(v=vs.100).aspx

– Main 메서드는 프로그램 제어가 시작되고 끝나는 .exe 프로그램의 진입점입니다.


– Main은 클래스 또는 구조체 내부에 선언됩니다.Main은 static이어야 하며 public이 아니어야 합니다.이전 예제에서 이 메서드에는 기본 액세스 수준인 private이 지정되었습니다. 이 메서드의 바깥쪽 클래스나 구조체는 정적일 필요가 없습니다.


– Main은 void 또는 int 반환 형식일 수 있습니다.


– Main 메서드는 명령줄 인수를 포함하는 string[] 매개 변수가 있거나 없는 상태로 선언할 수 있습니다.Visual Studio를 사용하여 Windows Forms 응용 프로그램을 만드는 경우 수동으로 매개 변수를 추가하거나 Environment 클래스를 사용하여 명령줄 인수를 가져올 수 있습니다.매개 변수는 명령줄 인수(0부터 시작)로 읽습니다. C 및 C++와 달리 프로그램의 이름은 첫 번째 명령줄 인수로 취급되지 않습니다. 


class Program
{
    static void Main(string[] args)
    {
        // Display the number of command line arguments:
        System.Console.WriteLine(args.Length);
    }
}



 

.Net namespace






























네임스페이스


설명


System


타입, 메모리 관리 핵심 클래스들


System.Collections


배열, 연결 리스트 등의 컬렉션 클래스


System.IO


파일 입출력 네트워크 관련 클래스


System.Windows.Forms


윈도우즈 폼과 컨트롤


System.Drawing


GDI+


System.Web


개발에 관련된 클래스


System.Xml


XML 관련 클래스들


System.Security


보안, 암호, 권한 관련 클래스


namespace

namespace (MSDN)
http://msdn.microsoft.com/ko-kr/library/0d941h9d(v=vs.100).aspx


namespace (C# Study)
http://csharpstudy.com/CSharp/CSharp-namespace.aspx

namespace (Hoons.net)
http://www.hoons.kr/Lecture/LectureMain.aspx?BoardIdx=43000&kind=53&view=0


namespace (Winapi)
http://www.winapi.co.kr/dotnet/book/2-3-1.htm



using System;


namespace ConsoleApplication1
{
  namespace A
  {
    class MyClass
    {
      int value = 1;
      public void MyMethod() { System.Console.WriteLine(value); }
    }
  }
  namespace B
  {
    class MyClass
    {
      double value = 2.1;
      public void MyMethod() { System.Console.WriteLine(value); }
    }
  }

  class Program
  {
    static void Main(string[] args)
    {

        A.MyClass a = new A.MyClass();
        a.MyMethod(); // 1 출력
        B.MyClass b = new B.MyClass();
        b.MyMethod(); // 2.1 출력
     }
  }
}




namespace SampleNamespace
{
    class SampleClass
    {
        public void SampleMethod()
        {
            System.Console.WriteLine(
              “SampleMethod inside SampleNamespace”);
        }
    }

    // Create a nested namespace, and define another class.
    namespace NestedNamespace
    {
        class SampleClass
        {
            public void SampleMethod()
            {
                System.Console.WriteLine(
                  “SampleMethod inside NestedNamespace”);
            }
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            // Displays “SampleMethod inside SampleNamespace.”
            SampleClass outer = new SampleClass();
            outer.SampleMethod();

            // Displays “SampleMethod inside SampleNamespace.”
            SampleNamespace.SampleClass outer2 = new SampleNamespace.SampleClass();
            outer2.SampleMethod();

            // Displays “SampleMethod inside NestedNamespace.”
            NestedNamespace.SampleClass inner = new NestedNamespace.SampleClass();
            inner.SampleMethod();
        }
    }
}