c# - Linq Merge 2 Lists to One -


this question has answer here:

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

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -