c# - lambda expression join list<object> with list<string> -


i have list<object> , list<string> records. want inner join both list.

following list records.

var listcontributiondetailstobeupdated = new list<contributiondetailmodel>  {     new contributiondetailmodel { employeenumber="1", employeefirstname="david", employeelastname="k", nhipnumber="nhi-100" },     new contributiondetailmodel { employeenumber="2", employeefirstname="xavior", employeelastname="f",nhipnumber="nhi-101"},     new contributiondetailmodel { employeenumber="3", employeefirstname="george", employeelastname="s", nhipnumber="nhi-102" },     new contributiondetailmodel { employeenumber="4", employeefirstname="pandit", employeelastname="h",nhipnumber="nhi-103"},     new contributiondetailmodel { employeenumber="5", employeefirstname="zania", employeelastname="d", nhipnumber="nhi-104" } };  var updatedrecored = new list<string> { "nhi-100", "nhi-101", "nhi-102" }; 

can 1 me inner join both list.

it's pretty straight-forward. select nhipnumber contribution details key joining:

var result = c in listcontributiondetailstobeupdated              join r in updatedrecored on c.nhipnumber equals r              select c; 

method syntax:

var result = listcontributiondetailstobeupdated      .join(updatedrecored, c => c.nhipnumber, r => r, (c, r) => c); 

you can use filtering instead of joining, it's not optimal way, because join set operation , uses internal lookup joined collection. simple filtering have complexity o(n*m) instead of o(n+m)

var result = listcontributiondetailstobeupdated      .where(c => updatedrecored.contains(c.nhipnumber)); 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -