码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-08-11 23:05:48      阅读:125      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!