code4it-dev / blog-comments

https://www.code4it.dev/
1 stars 0 forks source link

csharptips/sorted-set #20

Open utterances-bot opened 2 years ago

utterances-bot commented 2 years ago

C# Tip: Use a SortedSet to avoid duplicates and sort items - Code4IT

Using the right data structure is crucial to build robust and efficient applications. So, why using an List or an HashSet to sort items (and remove duplicates) when you have a SortedSet?

https://www.code4it.dev/csharptips/sorted-set

jamescurran commented 2 years ago

Please note: While the iterator for HashSet does appear to return the items in insertion order, this is merely an implementation detail, and not a guarantee, and the algorithm used might be changed in the future. The documentation for it specifically states that the "elements are in no particular order."

bellons91 commented 2 years ago

I didn't know that! Thanks for adding!

(as a reference for who's interested about that topic, here's the link to the documentation )