To select distinct elements based on one property of an object using LINQ in C#, you can use the Distinct()
method with a lambda expression as a parameter.
Assuming a class Person
with a Name
property, the following snippet would return all unique names:
main.cs376 chars14 lines
In this example, we select the Name
property of each Person
object using the Select()
method, and then call Distinct()
on the resulting sequence to get only unique names.
gistlibby LogSnag