Alex Rivera | Logout

How to hide some members of an interface

Asked 2011-03-12T19:08:31.180
14

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?

Edit
Report

2 Answers

1

You could make it empty or launch a NotImplementedException

answered 2011-03-12T19:15:01.223
0

What makes you so sure that you really need to implement ICollection? If you don't want some methods from this interface, don't use it, declare a new interface with methods that you want. The whole point of using ICollection is to make other objects think that they can do with your object whatever they can do with any other collection.

answered 2011-03-12T19:25:12.450

Your Answer