What are the key differences between Dictionary.Clear
and new Dictionary()
in C#? Which one is recommended for which cases?
I believe that .Clear() was provided so that if your Dictionary is exposed as a read-only property you would be able to remove all of the items. However, if it's not exposed that way, and you have complete control then it might be easier to just instantiate a new Dictionary. There might be a slight performance difference between the two, also.