Mid Collections

Can a HashSet<T> store duplicate values?

No, HashSet<T> does not allow duplicates. Attempting to add a duplicate value will

return false and not change the set.

bool added = uniqueNumbers.Add(2); // returns false because 2

already exists

More from C# Programming Tutorial

All questions for this course