HashSet<T> — unordered. SortedSet<T> — sorted.
HashSet:
SortedSet:
1// HashSet2var set = new HashSet<int> { 3, 1, 2 };3// Iteration: 3, 1, 2 (unordered)45// SortedSet6var sorted = new SortedSet<int> { 3, 1, 2 };7// Iteration: 1, 2, 3 (sorted)
Key: HashSet for fast lookup, SortedSet for order.