I have a string array of such type
String[] codes = { "a", "b" };
And the collection where Thing has property Code.
ICollection<Thing>
I want to take element from this collection if its code matches any element of array. How can i achieve this, because it seems that there is no method that can do such thing?
CodePudding user response:
you can find the first element
var firstElement= things.FirstOrDefault(t => codes.Contains(t.Code));
or list if it can be several
var elements= things.Where(t => codes.Contains(t.Code)).ToList();
