设计模式-7-原型模式
2016-06-15 23:08
225 查看
说明
通过对自身的浅层的克隆和深层的克隆,能在短期大量生成不同内存区域的相同值的对象
通过对自身的浅层的克隆和深层的克隆,能在短期大量生成不同内存区域的相同值的对象
public class PrototypeA { public int i { get; set; } public List<string> lstr { get; set; } public PrototypeA() { lstr = new List<string>(); } public PrototypeA Clone() { PrototypeA entity = (PrototypeA)this.MemberwiseClone(); entity.lstr = ((string[])this.lstr.ToArray().Clone()).ToList(); return entity; } public void Print() { foreach(var str in lstr) { Console.WriteLine(str); } Console.WriteLine(i); } } Console.WriteLine("---------------"); PrototypeA prototypeA = new PrototypeA(); prototypeA.i = 5; prototypeA.lstr.Add("1"); prototypeA.Print(); Console.WriteLine("---------------"); var proB = prototypeA.Clone(); proB.Print(); Console.WriteLine("---------------"); proB.i = 7; proB.lstr.Add("2"); proB.Print(); Console.WriteLine("---------------"); prototypeA.Print();
相关文章推荐
- apk 打包流程
- SQL Server 维护计划实现数据库备份(策略实战)
- Jquery源码解析-设计理念
- ESP8266-SDK编写的TM1668程序驱动数码管
- Python中print函数输出时的左右对齐问题
- Java MVC框架性能比较
- 常用命令 - 输入输出、执行状态
- apache 泛域名配置
- Apache配置
- 关于oracle用户进程,服务进程,后台进程
- 关于网关和子网掩码的总结
- D3.js学习04_enter,update,exit
- NS4-SSL证书的安装
- Android 自定义View(一)
- 第三节课作业
- 作业九:《软件工程》课程总结
- 【设计模式】工厂模式
- 使用javascript控制密码框获取焦点时文字消失,失去焦点时文字出现
- vivado----simulation上
- redis学习之redis的主从复制