Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个嵌套列表,里面有很多列表。我想检查这个嵌套列表是否包含特定的字符串值,哪个列表是存储在 .
if (!checkList.Any(s => s == "aaa")) { // do sth }
以上是检查普通列表而不是嵌套列表,谁能给我嵌套列表的答案?
使用嵌套Any:
Any
if (!checkList.Any(innerList => innerList.Any(s => s == "aaa")))
或者,您可以使用 aSelectMany来展平您的列表:
SelectMany
if (!checkList.SelectMany(innerList => innerList).Any(s => s == "aaa"))