Distinct in LINQ-C#

Viewed 15597

I have the below list and query expression to get the distinct list.

 List<LinqTest> myList = new List<LinqTest>();
 myList.Add(new LinqTest() { id = 1, value = "a" });
 myList.Add(new LinqTest() { id = 1, value = "b" });
 myList.Add(new LinqTest() { id = 2, value = "c" });
 myList.Select(m => new { m.id}).Distinct().ToList();

I have referred the below SO link linkfor the code. Even after using distinct() i'm getting 3 records with the duplicate values. what could be the reason?

6 Answers
Related