• 深度复制


     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 
  • 相关阅读:
    软件体系风格选择小结
    bert入门资料
    RNN入门和seq2seq
    推荐系统论文源码笔记——依次学习之DKN源码笔记
    Mac os下gcc编译错误解决方案
    ns3 安装方法
    angular http ajax header
    javascript 实现htmlEncode htmlDecode
    windows下的python扩展包下载地址
    php版DES
  • 原文地址:https://www.cnblogs.com/msnadair/p/1695474.html
Copyright © 2020-2023  润新知