To get unique values from a list using LINQ, you can use the Distinct
method which returns the distinct elements from a sequence by using the default equality comparer to compare values. Here is an example:
main.cs173 chars8 lines
This will output:
main.cs10 chars6 lines
You can also get unique elements based on a specific property of objects in a list using grouping. Here is an example:
main.cs416 chars16 lines
This will output:
main.cs18 chars3 lines
gistlibby LogSnag