Reputation: 3311
I have a list of strings and I need to check if specific items(not one item) exist in that list.
List<string> strings = new List<string>() {"one","two","three","four","five" };
I need to find out if "one" and "three" is in that list. Is it possible with one linq query?
Thanks for the help!
Upvotes: 8
Views: 19285
Reputation: 1066
var findMe = new List<string>() { "one", "three"};
List<string> strings = new List<string>() { "one", "two", "three", "four", "five" };
var result = findMe.All(f => strings.Any(s => f == s));
Upvotes: 3
Reputation: 236188
var valuesToCheck = new[] {"one", "three"};
bool isAllInList = valuesToCheck.All(s => strings.Contains(s));
Upvotes: 19