Bool list check if every item in list is false

后端 未结 4 669
轮回少年
轮回少年 2020-12-18 18:28

I have a List with lots of values. What is the most efficient way to check if every single item in the list equals false?

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-18 18:48

    You can use Enumerable.Any it will find satisfy the condition on first match. As Habib rightly said better to use Any as Enumerable.All would return true for an Empty list of bool.

    !lst.Any(c=> c == true);
    

    OR use Enumerable.All

    lst.All(c=> c == false);
    

提交回复
热议问题