深拷贝
来源:互联网 发布:淘宝模特快速拍照视频 编辑:程序博客网 时间:2024/05/01 11:20
浅拷贝示例:
//////////////////////////////////////////////////////////////////////////// 功能: 学习一下深拷贝.. // //////////////////////////////////////////////////////////////////////////using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Diagnostics; // 调试using System.Collections;namespace benben_CSharp_first{ class CDemo { public int[] intArray = new int[] { 0, 1, 2, 3, 4 }; public void showElement() { foreach (int iValue in intArray) { Console.Write("{0} ", iValue); } Console.WriteLine(); } } class Test { static void Main() { CDemo d_1 = new CDemo(); CDemo d_2 = d_1; d_1.showElement(); d_2.showElement(); // 修改 d_1 后再打印元素 d_1.intArray[0] = 100; d_1.showElement(); d_2.showElement(); // 注意这一行的打印输出也和上一行一样.. Console.ReadKey(); } }}
深拷贝示例:
//深拷贝示例: //////////////////////////////////////////////////////////////////////////// 功能: 学习一下深拷贝.. // //////////////////////////////////////////////////////////////////////////
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Diagnostics; // 调试using System.Collections;
namespace benben_CSharp_first{ class CDemo //: ICloneable { public int[] intArray = new int[] { 0, 1, 2, 3, 4 };
public void showElement() { foreach (int iValue in intArray) {
Console.Write("{0} ", iValue); } Console.WriteLine(); }
public object Clone() { CDemo cloner = new CDemo(); Array.Copy(this.intArray, cloner.intArray, this.intArray.Length); return cloner; }
}
class Test { static void Main() { CDemo d_1 = new CDemo(); CDemo d_2 = (CDemo)d_1.Clone(); d_1.showElement(); d_2.showElement();
// 修改 d_1 后再打印元素 d_1.intArray[0] = 100; d_1.showElement(); d_2.showElement(); // 注意这一行的打印输出也和上一行不一样. 说明是深拷贝.
Console.ReadKey(); } }}
- 深拷贝&&浅拷贝
- 深拷贝||浅拷贝
- 浅拷贝,深拷贝
- 浅拷贝,深拷贝
- 深拷贝,浅拷贝
- 浅拷贝 深拷贝
- 浅拷贝.深拷贝
- 浅拷贝 深拷贝
- 深拷贝,浅拷贝
- 深拷贝、浅拷贝
- 深拷贝、浅拷贝
- 深拷贝+浅拷贝
- 深拷贝 浅拷贝
- 浅拷贝、深拷贝
- 浅拷贝、深拷贝
- 深拷贝、浅拷贝
- 深拷贝,浅拷贝
- 深拷贝、浅拷贝
- easyui 编写的登陆框
- Android使用Zxing扫描二维码改成竖屏后,后面的预览画面出现了拉伸,扭曲的解决方法
- error C2039: “S_addr” : 不是“in_addr”的成员
- 中缀表达式转换为后缀表达式
- Ubuntu不得不分享的24条使用经验
- 深拷贝
- 从程序员到CTO的Java技术路线图
- android手机屏幕适配补充
- 在哪购买xml格式
- ubuntu环境下编译内核详解
- 什么是你的核心竞争力之一?
- Android AIDL接口定义语言
- IOS 下自动化测试框架 GHUnit 和 OCMock 初探 [一]
- Ural 1126. Magnetic Storms