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

    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());
      });

 

posted @ 2015-08-11 20:47  niaomingjian  阅读(1137)  评论(0编辑  收藏  举报