깊은 복사 [ Deep Delipcate ] [Deep Copy] :
데이터의 값 전체를 복사하는 것
얕은 복사[ Short Delipcate ] [Shallow Copy] :
참조를 복사하는 것
예시문
Struct VectorStruct {
public float x;
public float y;
public Vectorstruct (float x , float y) {
this.x = x;
this.y = y;
}
}
class VectorClass {
public float x;
public float y;
public VectorClass (float x , float y) {
this.x = x;
this.y = y;
}
}
main () {
VectorStruct d1 = new VectorStruct (15,15);
VectorStruct d2 = d1;
d1.x = 10;
ConsoleWriteLine(d2.x); // 15; 깊은 복사
VectorClass c1 = new VectorClass(15,15);
VectorClass c2 = c1;
c1.x = 10;
ConsoleWriteLine(c2.x); // 10; 얕은복사
c1.x = 10;
}
'프로그래밍 > C#' 카테고리의 다른 글
C# Property/Getter / Setter (0) | 2021.11.24 |
---|
댓글