I would like to create a custom collection that implements ICollection.
But I would like not to expose some memebers of ICollection like Clear method.
How to achieve this?
You can implement the interface explicitly and have the implementation hidden:
public class UrClass : ICollection
{
void ICollection.Clear() { ... }
}
The user can't call urClassInstance.Clear() directly, but they can call ((ICollection)urClassInstance).Clear() indirectly like this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With