05 原型模式/原型模式深复制/Program.cs
(开头部分) 1KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 原型模式深复制
{
/// <summary>
/// 深复制,副本对象指向一个复制过来的新对象,而不是原来对象的引用
/// </summary>
class Program
{
static void Main(string[] args)
{
TestClone();
TestCopy();
Console.ReadLine();
}
/// <summary>
/// 浅复制
/// </summary>
static void TestClone()
{
Console.WriteLine("******浅复制******");
Resume a = new Resume("大鸟");
a.SetPersonalInfo("男", "29");
a.SetWorkExperience("1998-2000", "广东公司");
Resume b = (Resume)a.Clone();
b.SetPersonalInfo("男", "24");
b.SetWorkExperience("2000-2008", "华为");
Resume c = (Resume)a.Clone();
c.SetPersonalInfo("男", "20");
c.SetWorkExperience("2001-2004", "腾讯");
a.Display();
b.Display();
c.Display();
}
/// <summary>
/// 深复制
/// </summary>
static void TestCopy()
{
Console.WriteLine("******深复制******");
Resume a = new Resume("大鸟");
a.SetPersonalInfo("男", "29");
a.SetWorkExperience("1998-2000", "广东公司");
Resume b = (Resume)a.Copy();
b.SetPersonalInfo("男", "24");
b.SetWorkExperience("2000-2008", "华为");
Resume c = (Resume)a.Copy();
c.SetPersonalInfo("男", "20");
c.SetWorkExperience("2001-2004", "腾讯");
后面还有 11 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。