게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
(c#)깊은 복사, 얇은 복사 이해가 잘 안가요
게시물ID : programmer_11499짧은주소 복사하기
작성자 : 으앙쥬거땅
추천 : 0
조회수 : 2870회
댓글수 : 14개
등록시간 : 2015/06/22 17:02:48
옵션
  • 본인삭제금지
namespace Study
{
    class MyClass
    {
        public int MyField1;
        public int MyField2;
        public MyClass Deepcopy()
        {
            MyClass newCopy = new MyClass();
            newCopy.MyField1 = this.MyField1;
          newCopy.MyField2 = this.MyField2;
          return newCopy; 
        }
    }
    class MainApp
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Shallo copy");
            {
                MyClass source = new MyClass();
                source.MyField1 = 10;
                source.MyField2 = 20;
                MyClass target = source;
                target.MyField2 = 30;
                Console.WriteLine("{0} {1}", source.MyField1, source.MyField2);
                Console.WriteLine("{0} {1}", target.MyField1, target.MyField2);
            }
            Console.WriteLine("Deep copy");
            {
                MyClass source = new MyClass();
                source.MyField1 = 10;
                source.MyField2 = 20;
                MyClass target = source.Deepcopy();
                target.MyField2 = 30;
                Console.WriteLine("{0} {1}", source.MyField1, source.MyField2);
                Console.WriteLine("{0} {1}", target.MyField1, target.MyField2);
            }
        }
    }
}
 
 
책에 있는 예제를 따라하는 중인데
굵은글씨 처리 된 곳이 이해가 잘 안가네요ㅠㅠ;;;
this가 자신을 가리키는 것은 알겠는데 여기서 this.MyFeild1과 2는 무엇인가요?
으으 머리가 잘 안돌아가네요...
전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호