Reputation: 107
I got a nested list with numbers of lists inside. I wanna check if this nested list contains a particular string value and it does not matter which list is the value stored in .
if (!checkList.Any(s => s == "aaa"))
{
// do sth
}
the above is to check normal list but not nested list, can anyone give me the answer for nested list?
Upvotes: 0
Views: 3171
Reputation: 54897
Use a nested Any
:
if (!checkList.Any(innerList => innerList.Any(s => s == "aaa")))
Alternatively, you may use a SelectMany
to flatten your list:
if (!checkList.SelectMany(innerList => innerList).Any(s => s == "aaa"))
Upvotes: 7