LINQ Distinct Method

In LINQ, the Distinct method or operator is used to get only the distinct elements from the collection.

Here is the pictorial representation of the LINQ Distinct method.

LINQ Distinct Method

The LINQ Distinct method or operator is used to get only the distinct elements from the collection.

Syntax of LINQ Distinct Method

Here is the syntax of using distinct methods to get unique elements from the collection.

In the above syntax, we applied distinct method on "numbers" collection to get only the distinct elements from the collection.

Example of LINQ Distinct Method

Here is the example of the LINQ Distinct Method.

In the above example, we applied a Distinct method with StringComparer.OrdinalIgnoreCase case property, otherwise, it will perform the operation with case sensitivity on"countries" collection, and it will treat "India" and "india" as different.

Output:

LINQ Distinct Method
Next TopicLINQ Except Method




Latest Courses