c샵
C# 클래스 끼리 값 대입시 주의
나도아프네
2017. 4. 18. 21:55
class clTest
{
public string student;
}
clTest _clTestA = new clTest();
clTest _clTestB = new clTest();
_clTestB.student = "B";
_clTestA = _clTestB; <-------- (1)
_clTestB.student = "BB"; <--- 여기 바꾸면 (1) 의 _clTestA.student 도 "BB"가 된다.
클래스간의 대입은 같은 포인터주소가 되는것 같다.
그래서
clTest _clTestA = new clTest();
clTest _clTestB = new clTest();
_clTestB.student = "B";
_clTestA = _clTestB;
_clTestB = new clTest(); <---------재 할당하여 사용하였다.
_clTestB.student = "BB";