I have class myCollection that inherit from Dictionary.
Want to hide the add method in myCollection.
Used the private new modifier but its still visible.
Is this not possible ?
baseclass
public void Add(TKey key, TValue value) { Insert(key, value, true); }
mycollection
private new void Add(string key, MyOtherClass myClass) { base.Add(key, myClass); }
No, this is not possible.
You can’t change the accessibility of an inherited member.
You can use composition instead of inheritance and only expose the functionality you want (by delegating calls to the composed object). This may not be an option if you rely on the inheritance chain elsewhere in your code.