Exemplo n.º 1
0
        static void Main(string[] args)
        {
            TestCopy a = new TestCopy();

            a.x = 50;
            a.y = 99;
            Console.WriteLine("{0} {1}", a.x, a.y);

            TestCopy b = a; // Shallow Copy

            b.x = -9;
            Console.WriteLine("{0} {1}", a.x, a.y);
            Console.WriteLine("{0} {1}", b.x, b.y);



            TestCopy c = new TestCopy();

            c.x = 55;
            c.y = 3;
            Console.WriteLine("{0} {1}", c.x, c.y);

            TestCopy d = c.HardCopy(); // Deep Copy

            // d.x == 55, d.y == 3
            d.x = -99;
            Console.WriteLine("{0} {1}", c.x, c.y);
            Console.WriteLine("{0} {1}", d.x, d.y);
        }
Exemplo n.º 2
0
        public TestCopy HardCopy()             // 깊은 복사 메소드
        {
            TestCopy newCopy = new TestCopy(); // 객체 생성

            newCopy.x = this.x;
            newCopy.y = this.y;

            return(newCopy);
        }