> I have a C# collection class that inherits from SortedList. I want to be
> able to hide certain methods such as Add. How do I do that?

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
To elaborate on Jon's reply: Create a new class that does not *inherit*
SortedList, but *contains* a SortedList instance in it. You can expose the
attributes of SortedList via the new class, and not expose those which you
want to hide.
In addition, you may want to implement some of the interfaces that
SortedList implements, for a variety of reasons.
I recently had a similar problem when creating a Generic HistoryList
Collection. There is no such Collection in the Framework. A HistoryList is a
Collection which has a limited capacity, and can grow to that capacity, but
no larger. When it reaches Capacity, it removes items from the beginning of
the list to make room for new ones. In addition, it has a Position, which
indicates the current Position in the list, to allow for both undoing and
redoing. One can move the Position backwards and forwards in the list. When
one adds an item at a Position which is not the end, all items from that
point forward are removed.
I looked at a number of different Generic Lists, Collections, and
Interfaces, and determined that the Generic List was my best place to start.
I created the List as a protected member, and exposed the method, properties
etc., which were relevant while hiding others. I then added methods,
properties, etc., which provided the "HistoryList-specific" functionality
required. I also implemented the IEnumerable, ICollection, and IList
interfaces, to make it useful in a variety of situations which require
interfaces.

Signature
HTH,
Kevin Spencer
Microsoft MVP
Professional Numbskull
Show me your certification without works,
and I'll show my certification
*by* my works.
>> I have a C# collection class that inherits from SortedList. I want to be
>> able to hide certain methods such as Add. How do I do that?
[quoted text clipped - 7 lines]
> bad form, as anyone who received your object as a SortedList would
> expect to be able to add to it.
Dave - 26 Mar 2006 19:19 GMT
Thanks for the detailed replies.
Aggregation/composition will be the way to go. This collection needs to be
remotable anyway so I'm already providing methods on another class to do
things like Add.