I would use Distinct , and then, for example, check against count:
bool bAreAllPeopleUnique = (personList.Distinct(p => p.ID).Count == personList.Count);
However, as @Ian commented, you need to add a property to the Person class so that you can access the Id like this:
public string ID { get { return _id; } }
"Better" to implement this would be to add a method like this:
private bool AreAllPeopleUnique(IEnumerable<Person> people) { return (personList.Distinct(p => p.ID).Count == personList.Count); }
NOTE. The method accepts an IEnumerable not a list, so any class that implements this interface can use this method.
source share