Search code examples
c#.netcollectionsgenerics

SortedSet<T> vs HashSet<T>


My question is that what is the need of HashSet<T> when we have SortedSet<T>! All HashSet's methods are available in SortedSet too, moreover SortedSet is advantageous as it provides collection already in sorted manner! Even then HashSet is present. For what is it useful then?


Solution

  • If you don't need sorting, you shouldn't use a class that does sorting because that means your application will be doing more work than it needs to. (It will make your app faster, in other words).