LINQ Distinct MethodIn 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. The LINQ Distinct method or operator is used to get only the distinct elements from the collection. Syntax of LINQ Distinct MethodHere 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 MethodHere 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:
Next TopicLINQ Except Method
|