惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
I
InfoQ
宝玉的分享
宝玉的分享
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
P
Privacy International News Feed
T
Threatpost
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
Vulnerabilities – Threatpost
NISL@THU
NISL@THU
aimingoo的专栏
aimingoo的专栏
S
Schneier on Security
C
Cisco Blogs
T
The Blog of Author Tim Ferriss
Simon Willison's Weblog
Simon Willison's Weblog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Jina AI
Jina AI
雷峰网
雷峰网
Know Your Adversary
Know Your Adversary
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
I
Intezer
博客园 - Franky
博客园 - 【当耐特】
Hugging Face - Blog
Hugging Face - Blog
The Hacker News
The Hacker News
K
Kaspersky official blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
T
Tailwind CSS Blog
Project Zero
Project Zero
T
Tor Project blog
B
Blog RSS Feed
Recorded Future
Recorded Future
Scott Helme
Scott Helme
美团技术团队
V
V2EX
V
Visual Studio Blog
L
Lohrmann on Cybersecurity
P
Proofpoint News Feed
D
DataBreaches.Net
The Register - Security
The Register - Security
M
MIT News - Artificial intelligence
L
LangChain Blog
Cisco Talos Blog
Cisco Talos Blog
博客园 - 三生石上(FineUI控件)
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
C
Cyber Attacks, Cyber Crime and Cyber Security
博客园_首页
P
Privacy & Cybersecurity Law Blog

博客园 - 天生舞男

多个平均数列的子查询 迁移sharepoint Sharepoint迁移数据库之绝版(只要照着做,一定能够迁移成功) Sharepoint的webpart 虚函数和非虚函数的调用基本原则 The visio to drawing project chart. - 天生舞男 Using MSChart from a C# WinForm 学习程序的自我建议---从实际软件的源代码开始学习 MS bug "The connection pool" in Oracle 10g and the data sort according to specified filed on DataGrid control. How to get response content with specified post data by post method Post method tip automation服务器不能创建对象 Get the biggest common divisor rose破解 ArrayList按Index删除的问题 Recently expection RadioButtonList中选择框和文字对不齐的解决办法 resolve problem best method is find document from official document 看了宝玉的作品,心理甚是感叹
About the deeply copy
天生舞男 · 2006-03-23 · via 博客园 - 天生舞男

Posted on 2006-03-23 15:24  天生舞男  阅读(385)  评论()    收藏  举报

In our program, we want to copy a object fully, and the object is nested, so when we design the class can using the copy constructor, there is a sample, you can run the code with CLR:

using
System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;namespace WebApplicationTest
{
 
/// <summary>
  /// Summary description for TestDeepCopy.
  /// </summary>
 
public class TestDeepCopy: System.Web.UI.Page
  {
   
private void Page_Load(object sender, System.EventArgs e)
    {
     
ClassLevel1 objClassLevel1 = new ClassLevel1();
     
objClassLevel1.objClassLevel2 = new ClassLevel2();
     
objClassLevel1.objClassLevel2.objClassLevel3 = new ClassLevel3();
     
objClassLevel1.objClassLevel2.strClassLevel2 = "I am a string in level2 class";
      
      // using the instance of the ClassLevel1 to call
      // the copy constructor of ClassLevel1 class
     
ClassLevel1 copyObjClassLevel1 = new ClassLevel1(objClassLevel1);
     
Response.Write(copyObjClassLevel1.objClassLevel2.strClassLevel2);
    }
#region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
     
//
      // CODEGEN: This call is required by the ASP.NET Web Form Designer.
      //
     
InitializeComponent();
     
base.OnInit(e);
    }
/// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
   
private void InitializeComponent()
    {
     
this.Load += new System.EventHandler(this.Page_Load);
    }
   
#endregion
 
}public class ClassLevel3
  {
    // Member variable
   
public string strClassLevel3;
    
    // Copy constructor
   
public ClassLevel3(ClassLevel3 objClassLevel3)
    {
     
this.strClassLevel3 = objClassLevel3.strClassLevel3;
    }
    
    // Default constructor
   
public ClassLevel3(){}
  }
public class ClassLevel2
  {
    // Member variable
   
public string strClassLevel2;
   
public ClassLevel3 objClassLevel3;
    
    // Copy constructor
   
public ClassLevel2(ClassLevel2 ojbClassLevel2)
    {
     
this.strClassLevel2 = ojbClassLevel2.strClassLevel2;
     
this.objClassLevel3 = new ClassLevel3(ojbClassLevel2.objClassLevel3);
    }
    
    // Default constrcutor
   
public ClassLevel2(){}
  }
public class ClassLevel1
  {
    // Member variable
   
public string strClassLevel1;
   
public ClassLevel2 objClassLevel2;
    
    // Copy constructor 
   
public ClassLevel1(ClassLevel1 ojbClassLevel1)
    {
     
this.strClassLevel1 = ojbClassLevel1.strClassLevel1;

      //Call the Copy constructor of ClassLevel2

this.objClassLevel2 = new ClassLevel2(ojbClassLevel1.objClassLevel2);
    }
    
    // Default constructor 
   
public ClassLevel1(){}
  }
}