Exemple #1
0
        static void Main(string[] args)
        {
            var student = new Student {
                Name = "张三", Age = 20
            };

            var studentB = student.Clone() as Student;

            studentB.Name = "李四";
            var studentC = student.Clone() as Student;

            studentC.Name = "王五";

            Console.WriteLine($@"{student.Name}*****{student.Age}");
            Console.WriteLine($@"{studentB?.Name}*****{studentB?.Age}");
            Console.WriteLine($@"{studentC?.Name}*****{studentC?.Age}");

            Console.WriteLine("***********************************");

            var newStudent = new NewStudent("张三");

            newStudent.SetStudent("张三", 15);
            newStudent.SetInterest("打篮球");
            var newStudentB = (NewStudent)newStudent.Clone();

            newStudentB.SetInterest("打乒乓球");
            newStudent.DisPlay();
            newStudentB.DisPlay();
            Console.ReadKey();
        }
Exemple #2
0
        public object Clone()
        {
            var student = new NewStudent(this.interest);

            student.name = this.name;
            student.age  = this.age;
            return(student);
        }