[英]Check if following items exist in the List<T>
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? 是否可以使用一个linq查询?
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));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.