I have a Class called Person
class Person() {
string Name;
string SSN;
}
as well as a List That Contains many common instances of the Person class that are duplicates. For Example
Person.Name = "John";
Person.SSN = "123456789";
Person.Name = "John";
Person.SSN = "123456789";
Person.Name = "John";
Person.SSN = "123456789";
Person.Name = "John";
Person.SSN = "123456789";
Person.Name = "John";
Person.SSN = "123456789";
I am trying to figure the syntax out for a Linq statement to just take one of the class objects in the List when common and add it to a new list.
List<Person> newPerson = new List<Person>();
newPerson.AddRange(person.GroupBy(x => x.Name, x => x.SSN).Select(grp => grp.ToList().First()).ToList());
Thanks