Using C # 3 and .Net Framework 3.5, I have a Person object
public Person { public int Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public int SSN { get; set; } }
and I have a List of them:
List<Person> persons = GetPersons();
How can I get all Person objects in faces where the SSN is not unique in the list and remove them from the list of faces and ideally add them to another list called " List<Person> dupes "?
The original list might look something like this:
persons = new List<Person>(); persons.Add(new Person { Id = 1, FirstName = "Chris", LastName="Columbus", SSN=111223333 }); // Is a dupe persons.Add(new Person { Id = 1, FirstName = "EE", LastName="Cummings", SSN=987654321 }); persons.Add(new Person { Id = 1, FirstName = "John", LastName="Steinbeck", SSN=111223333 }); // Is a dupe persons.Add(new Person { Id = 1, FirstName = "Yogi", LastName="Berra", SSN=123456789 });
And the end result will be Cummings and Berra on the list of original people and will have Columbus and Steinbeck on the list called cheating.
Many thanks!
Chris conway
source share