How to filter list so that if there are objects with same values in fields? [Answered]
Is there a way to filter objects so that objects with same field values are not duplicated in a list?
```cs
var a = new Person(){Name="john", Age=22};
var b = new Person(){Name="john", Age=22};
var myList = new List<Person>(){a,b};
// what LINQ code to put here so that there are no duplicates?
4 Replies
look up LINQ's Distinct method
What if the name is the same but the age is different?
or vice versa
are those considered unique values?
Distinct()
works fine if Person
is a record, btw
as it supports value equality out of the boxor if the Equals Method is overridden
✅ This post has been marked as answered!