C# 참조자복사

C#' 2015. 11. 6. 13:38

class Point

{

public int x;

public int y;

 

public Point()

{

x = 0;

y = 0;

}

public Point(int x, int y)

{

this.x = x;

this.y = y;

}

}

class Program

{

static void Main()

{

Point pt1 = new Point();

System.Console.WriteLine("({0}, {1})", pt1.x, pt1.y);

 

Point pt2 = new Point(5, 5);

System.Console.WriteLine("({0}, {1})", pt2.x, pt2.y);

 

pt1 = pt2; // 참조 복사

System.Console.WriteLine();

System.Console.WriteLine("({0}, {1})", pt1.x, pt1.y);

System.Console.WriteLine("({0}, {1})", pt2.x, pt2.y);

}

}

pt1 에 pt2를 복사한다는 것이, 객체 값을 복사하는게 아니라 참조를 복사하는 것이다.

 

pt2가 참조자인데 참조자를 복사하는 것이다.

 

'C#'' 카테고리의 다른 글

C# function  (0) 2015.11.07
C# DLL파일 만들기 와 만드는 이유  (0) 2015.11.06
C# 클래스  (0) 2015.11.06
C# 변수와 상수  (0) 2015.11.06
C# WriteLine 문자,문자열,상수,실수,진위형 출력  (0) 2015.11.06
블로그 이미지

왕왕왕왕

,