How to use TrueForAll

c#, list

Solution

Use `All`:

bool alltrue = listOfBools.All(b => b);

It will return `false` one the first `false`.

However, since you are actually using a `List<bool>` you can also use `List.TrueForAll` in the similar way:

bool alltrue = listOfBools.TrueForAll(b => b);

But since that is limited to a list i would prefer `Enumerable.All`.

Problem

I have a list of bools and I want to check if every one is set to true. I can run a loop and check it that way but I want to try to do it with `TrueForAll` method of a list. I need a predicate for that but I couldn't find a clear example for such a simple task as this.

Original source