Reputation: 4862
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); }
Upvotes: 2
Views: 150
Reputation: 5825
It's not hidden because the method signature of the Add in baseclass doesn't match that of the method in the mycollection class.
Upvotes: 0
Reputation: 499352
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.
Upvotes: 7