• Code-Function:深度复制


    ylbtech-Code-Function:深度复制
    1.返回顶部
    1、
    using System;
    
    namespace Sp.Common
    {
        public class FunctionHelper
        {
            /// <summary>
            /// 深度复制
            /// </summary>
            /// <typeparam name="T">The type of object being copied.</typeparam>
            /// <param name="source">The object instance to copy.</param>
            /// <returns>The copied object.</returns>
            public static T Clone<T>(T source)
            {
                if (!typeof(T).IsSerializable)
                    throw new ArgumentException("The type must be serializable.", "source");
    
                // Don't serialize a null object, simply return the default for that object
                if (Object.ReferenceEquals(source, null))
                    return default(T);
    
                System.Runtime.Serialization.IFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                System.IO.Stream stream = new System.IO.MemoryStream();
                using (stream)
                {
                    formatter.Serialize(stream, source);
                    stream.Seek(0, System.IO.SeekOrigin.Begin);
                    return (T)formatter.Deserialize(stream);
                }
            }
    
        }
    }
    2、
    2.返回顶部
     
    3.返回顶部
     
    4.返回顶部
     
    5.返回顶部
     
     
    6.返回顶部
     
    warn 作者:ylbtech
    出处:http://ylbtech.cnblogs.com/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    二叉搜索树
    splay模板
    树状数组模板
    K尾相等数
    寻找最大数
    布线问题(最小生成树)
    开心的小明
    独木舟上的旅行(二)
    The Triangle(记忆化搜索)
    喷水装置(二)
  • 原文地址:https://www.cnblogs.com/storebook/p/12685094.html
Copyright © 2020-2023  润新知