From the course: .NET Essentials: Working with LINQ

Unlock this course with a free trial

Join today to access over 22,400 courses taught by industry experts.

The Except method

The Except method

- [Instructor] Let's take a look at the except set operator. It takes two sequences and returns members of the first sequence that don't appear in the second sequence. Now, in this example, I'm going to call it twice on these numbers, these numbers, integers, numbersA and numbersB, and I'm reversing the order that I'm calling those in. In the first query, I'm saying numbersA except numbersB, and then I'll call numbersB except numbersA because I'll get a different list, right? There's unique numbers that are in set A that don't belong in set B, but remember, it turns to members of the first set that don't appear in the second set. So I when I run this, in the first results, I get zero two, four, and six, and in the second set of results, I get one, three, and seven.

Contents