Clone

public static void Main(string[]args)
        {
          

            Person student = new Person();
            student.Name = "甘全福";
            student.Age = 23;
            Person teacher = student.Clone();

            Console.WriteLine("姓名:"+teacher.Name + "年龄:" + teacher.Age);
            Console.WriteLine("克隆成功!");
         
            Console.Read();
        }

 

        class Person
        {
            public string Name { get; set; }
            public int Age { get; set; }

            public Person()
            {
               
            }

            public Person(string name,int age)
            {
                this.Name = name;
                this.Age = age;
            }

            public Person Clone()
            {
                Person p = new Person();
                p.Name = this.Name;
                p.Age = this.Age ;
                return p;
            }

        }

posted @ 2013-04-09 18:26  Predator  阅读(122)  评论(0编辑  收藏  举报