Is there a collection in C# that will not let you add duplicate items to it? For example, with the silly class of
public class Customer {
public string F
HashSet is what you're looking for. From MSDN (emphasis added):
The
HashSetclass provides high-performance set operations. A set is a collection that contains no duplicate elements, and whose elements are in no particular order.
Note that the HashSetbool -- true if the item was added to the collection; false if the item was already present.