首页 > 其他 > 详细

优雅地对泛型List 进行深拷贝

时间:2015-08-11 23:04:50      阅读:288      评论:0      收藏:0      [点我收藏+]
    public class People
    {
        public string Name;
        public int Age;

        public People(string name, int age)
        {
            this.Name = name;
            this.Age = age;
        }

        public People Clone()
        {
            return new People(this.Name, this.Age);
        }
    }

      List<People> pList = new List<People>();
      pList.Add(new People("A", 10));
      pList.Add(new People("B", 20));
      pList.Add(new People("C", 30));

      List<People> pList2 = new List<People>(pList.Count);
      // 拷贝
      pList.ForEach(delegate(People item)
      {
          pList2.Add(item.Clone());
      });

 

优雅地对泛型List 进行深拷贝

原文:http://www.cnblogs.com/niaomingjian/p/4722288.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!