Linq By Example

All

Used to determine if all items match a predicate condition.

All Elements

All can be used to ensure that all items match the defined condition.
    
using System;
using System.Collections.Generic;
using System.Linq;

var myList = new List();
myList.Add(1);
Console.WriteLine(myList.All(x => x == 1)); //Writes true. 

myList.Add(2);
Console.WriteLine(myList.All(x => x == 1)); //Writes false.

  

Empty Lists

It is important to note a quirk when using the All LINQ method against an empty list. No matter the condition, if ran against an empty list, the All statement will always return true. See below the example against an empty list that always returns true.
    
using System;
using System.Collections.Generic;
using System.Linq;

var myList = new List();
Console.WriteLine(myList.All(x => x == 1)); //Writes true. 

  

All vs Any

All can be seen as the opposite of the Any LINQ statement. There is no performance gain when using one or the other when inverting the condition as the predicate is still ran one by one against each item in the list.

However, you will usually find that code quality tools such as ReSharper flag this as if(somethingistrue) is easier to read than if(!issometingfalse)
    
using System;
using System.Collections.Generic;
using System.Linq;

var myList = new List();
myList.Add(1);

Console.WriteLine(!myList.Any(x => x == 1)); //Writes false (Notice the !)

Console.WriteLine(myList.All(x => x != 1)); //Writes false