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?
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"))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.