C# Update a List from Another List

后端 未结 5 1370
别跟我提以往
别跟我提以往 2020-12-16 12:50

I have 2 List. The first one, lets call it ListA is more like a complete list and the second one ListB is a modified list. Now what I want to do i
5条回答
  •  隐瞒了意图╮
    2020-12-16 13:23

    to elaborate aershov's answer:

    ListA.Where(d => d.Name == x.Name).First().CopyFrom(x);
    

    then in your Person class:

    public class Person
    {
       // ... Name, Id, Age properties...
    
       public void CopyFrom(Person p)
       {
          this.Name = p.Name;
          this.Id = p.Id;
          this.Age = p.Age;
       }
    }
    

    of course check nulls and everything.

提交回复
热议问题