How to best prevent adding content to a dictionary
c#
Solution
Just encapsulate the dictionary within a custom class, and don't provide a way to add.
That being said, if there are always only three values, I would consider just using a class with three properties instead of a dictionary. There is no point in making a dictionary if the keys are fixed and known in advance - three properties will have a simpler, less error prone API and be more efficient.
Problem
I have a dictionary object with three key/value pairs. I want the values to be able to be modified, but i want to prevent being able to add more. Is there a best approach to prevent adding new key/value pairs? I was thinking of just hiding the Add method.