c# - How to simplify the code Using LINQ -
c# - How to simplify the code Using LINQ -
i need know how implement below logic list of items help of linq without using foreach
. also, need exclude matching items item
list after adding item new list.
code
list<stockresult> stockres = new list<stockresult>(); foreach (var stkitms in item) { if (db.stk.any(a => a.ino == stkitms.itemnum)) { stockresult ss = new stockresult(); ss.itemnumber = stkitms.itemnum; ss.filename = stkitms.filename; stockres.add(ss); } }
any solution appreciated.
you seek one:
list<stockresult> stockres = item.where(x=>db.stk.any(a => a.ino == x.itemnum)) select(x=> new stockresult() { itemnumber = x.itemnum, filename = x.filename }).tolist();
c# linq
Comments
Post a Comment