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!
var valuesToCheck = new[] {"one", "three"};
bool isAllInList = valuesToCheck.All(s => strings.Contains(s));
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));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With