c# - Linq Merge 2 Lists to One -
this question has answer here:
- how merge 2 lists using linq? 1 answer
- how perform merge sort using linq? 5 answers
i have 2 list example: 1:
id | number ------------- 01 | 20 02 | 50 04 | 2500
2:
id | number ------------- 01 | 10 02 | 20 03 | 1500
and final list want is:
id | number ------------- 01 | 30 02 | 70 03 | 1500 04 | 2500
how can done linq?
you can use zip
method.
public class myclass { public int id { get; set; } public string number { get; set; } }
then try this:
list<myclass> fist = new list<myclass>(); //add data list<myclass> second = new list<myclass>(); //add data fist.zip(second, (i1, i2) => new myclass() { id = i1.id, number = i1.number + i2.number });
Comments
Post a Comment