I'm working in C# and I'm not quite sure how to word this question (which made it hard to search). Basically I have a class that inherits from Dictionary<string,MyButton>
, where MyButton
is a class I made. However I want to overwrite the Add function to prevent adding keyvalue pairs that don't meet specific requirements (e.x. all MyButton values in the dictionary have size properties of which are all the same). I know how to overwrite the Add function with the New
operator however I'm not sure how to overwrite the constructor of the Dictionary class that allows one to do this, for example:
Dictionary<string, int> d = new Dictionary<string, int>()
{
{"cat", 2},
{"dog", 1},
{"llama", 0},
{"iguana", -1}
};
I'm not sure which constructor allows you to do the above. I believe it's this constructor but I'm not sure how to override it, or even how to make one.
Any help would be appreciated.
Thanks!