繁体   English   中英

检查列表中是否存在以下项目<T>

[英]Check if following items exist in the List<T>

我有一个字符串列表,我需要检查该列表中是否存在特定项目(不是一个项目)。

List<string> strings = new List<string>() {"one","two","three","four","five" };

我需要找出该列表中是否有“一个”和“三个”。 是否可以使用一个linq查询?

谢谢您的帮助!

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM