LINQ Except Query Operator

By Peter Bromberg

The Except operator produces the set difference between two sequences. It will only return elements in the first sequence that don't appear in the second. You can optionally provide your own equality comparison function.

public static void ExceptTest() {
    int[] first  = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
    int[] second = new int[] {             4, 5, 6,         10 };

     var q = first.Except(second);

    foreach (var num in q)
       Console.WriteLine(num);

   Console.ReadLine();
}

LINQ Except Query Operator  (1207 Views)