Beispiel #1
0
        public object Clone()
        {
            Resume1 resume1 = new Resume1(this.work);

            resume1._name   = this._name;
            resume1.Address = this.Address;
            return(resume1);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            //ConcretePortotype concrete = new ConcretePortotype("112");
            //var concrete2 = (ConcretePortotype)concrete.Clone();

            //Console.WriteLine(concrete.ID);
            //Console.WriteLine(concrete2.ID);

            //Console.ReadKey();

            #region 浅表复制

            // var start = DateTime.Now;
            //var resume = new Resume("张三");
            //resume.SetExperience("chinese company", "China");


            ////一般在初始化的信息不发生变化的情况下,克隆是最好的办法,这既隐藏了对象创建的细节,又能调高性能
            //var r2 = (Resume)resume.Clone();
            //resume.SetExperience("american company", "China");
            //resume.Display();
            //r2.Display();
            ////var resume1 = new Resume("张四");
            ////resume1.Experience = "C# 工作5年";
            ////resume1.Display();
            //Console.WriteLine($"it took {(DateTime.Now - start).TotalMilliseconds} millseconds ");
            //Console.ReadKey();

            //var start = DateTime.Now;
            //var resume = new Resume("张三");
            //resume.SetExperience("chinese company", "China");

            #endregion
            var start  = DateTime.Now;
            var resume = new Resume1("张三");
            resume.SetExperience("chinese company", "China");
            //一般在初始化的信息不发生变化的情况下,克隆是最好的办法,这既隐藏了对象创建的细节,又能调高性能
            var r2 = (Resume1)resume.Clone();
            r2.SetExperience("american company", "China");
            resume.Display();
            r2.Display();

            Console.WriteLine($"it took {(DateTime.Now - start).TotalMilliseconds} millseconds ");
            Console.ReadKey();
        }