
SortedList, Why Parenthesis instead of Brackets?
public class SortedList : IDictionary, ICollection, IEnumerable, ICloneable
I'm not sure what you're referring to in this posting, because SortedList
does indeed use []'s... however, SortedList actually contains 2 arrays, one
with keys and one with values (as ICollection objects).
Using the SortedList[key] (see listing for 'Item' in class descriptions)
returns the value.
There are 4 interesting methods:
GetKey(int index) will also return the key at the index given.
GetByIndex(int index) will return the value at the index given.
*** GetValue is, unfortunately, used in IDictionary. It would have been a
nicely symmetric method name here. ***
GetKeyList() returns an IList interface, which gives access to the Keys,
using []
GetValueList() returns and IList interface, which gives access to the
Values, using []
IndexOfKey(object key) and IndexOfValue(object value) round out the classes
ability to find each index, key, and value in the list.
Thus, this is a more complex class that Array or ArrayList, yet tends to be
easy to use.
Quote:
> I was looking at the SortedList and it uses Parenthesis () instead of []
in
> order to use its Indexer.
> Arrays and ArrayList use the [].
> Just wondering why this is?
> Thanks.