The Except operator returns a sequence that contains all the elements of a first sequence that do not exist in a second sequence.
An element is determined to be equal to another element using their GetHashCode and Equals methods.
public static IEnumerable<T> Except<T>( this IEnumerable<T> first, IEnumerable<T> second);
ArgumentNullException is thrown if any arguments are null.
The following code shows how to use Except operator.
using System; using System.Linq; using System.Collections; using System.Collections.Generic; class Program/*from w w w.j av a 2s. co m*/ { static void Main(string[] args) { string[] codeNames = {"Python", "Java", "Javascript", "Bash", "C++", "Oracle"}; // First generate a processed sequence. IEnumerable<string> processed = codeNames.Take(4); IEnumerable<string> exceptions = codeNames.Except(processed); foreach (string name in exceptions) Console.WriteLine(name); } }