zoukankan      html  css  js  c++  java
  • 深度复制

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Text;
     4 using System.IO;
     5 using System.Runtime.Serialization.Formatters.Binary;
     6 
     7 namespace WinFormTest
     8 {
     9     [Serializable]
    10     public class Class1:ICloneable 
    11     {
    12         private string _t1;
    13         private string _t2;
    14         private Class2 _c2;
    15 
    16         public string T1
    17         {
    18             get
    19             {
    20                 return _t1;
    21             }
    22             set
    23             {
    24                 _t1 = value;
    25             }
    26         }
    27 
    28 
    29         public string T2
    30         {
    31             get
    32             {
    33                 return DateTime.Now.ToString();
    34             }
    35           
    36         }
    37 
    38         public Class2 C2
    39         {
    40             get
    41             {
    42                 return _c2;
    43             }
    44             set
    45             {
    46                 _c2 = value;
    47             }
    48         }
    49 
    50         public Object Clone()
    51         {
    52             {  
    53                 MemoryStream stream = new MemoryStream();
    54                 BinaryFormatter formatter = new BinaryFormatter();
    55                 formatter.Serialize(stream, this);
    56                 stream.Position = 0;
    57                  
    58                 return formatter.Deserialize(stream);
    59             }
    60         }
    61     
    62     }
    63 }
    64 
  • 相关阅读:
    [转]项目需求范围管理
    JavaScript 王者归来
    [转]大文件上传组件
    [转]使用vs2005自带的sql2005 express
    JS判断Caps Lock
    [转]Web项目管理思考
    [转]JS严格验证身份证
    两分钟用C#搭建IE BHO勾子, 窃取密码
    asp.net性能提升十个方法(Microsoft)
    [转]Asp.net 将js文件打包进dll 方法
  • 原文地址:https://www.cnblogs.com/msnadair/p/1695474.html
Copyright © 2011-2022 走看看