I have a dictionary that I would like to pass externally through a property but I would like to limit some features like the clear method. Here's the code that i've implemented.
// dictionary private declaration inside the class
private Dictionary<int, string> _value = new Dictionary<int, string>();
// here's the property declaration for access the dictionary outside the class
public new Dictionary<int, string> Value
{
get
{
return _value;
}
set
{
// here is where i'd like to avoid some dictionary features like clear() and give only the opportunity to add or change existing values
_value = value;
}
}
It’s possible through the “set” of this property to limit some of the features of the dictionary? Maybe using a switch or an if statement?