From the course: .NET Essentials: Working with LINQ

Unlock this course with a free trial

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

The Distinct method

The Distinct method

- In this chapter, we're looking at the set operators. And the idea here is you have a single sequence, or you might have multiple sequences, and you're going to look through those sequences and you're going to build on a new set of information based on some criteria. If you've studied set theory, you've heard terms like union or intersect, and there are similar operations in link. We're going to start by looking at a simple one that looks for unique values is called distinct, and the way I call it is with the extension method syntax. So here let's run the query, I started off with this data at one, two, two, one three, five, five, six. I call distinct on that, and that will remove all the duplicate values. So I end up with a set of data, that contains these unique values, One, two, three, five, and six. Now this is easy to understand when I'm working with integers or doubles or numeric values but again, if you're…

Contents