c# - How to find a match with 2 comma separated strings with LINQ -
i new linq.
i trying compare 2 comma separated strings see if contain matching value.
i have string contains list of codes. masterformlist = "aaa,bbb,ccc,fff,ggg,hhh"
i trying compare list of objects. in given field formcode contains comma separated string of codes. want see if @ lease 1 code in string in masterformlist. how write linq accomplish this?
right have:
resultslist = (from r in resultslist r.formcodes.split(',').contains(masterformlist) select r).tolist();
it not return matching items list.
please advise
you'd need build collection of items search for, check see if there contained within set:
var masterset = new hashset<string>(masterformlist.split(',')); resultslist = resultslist .where(r => r.formcodes.split(',') .any(code => masterset.contains(code))) .tolist();
Comments
Post a Comment