Why not just use a SortedList<TKey,TValue>?
KeyedCollection<TKey,TValue> is dictionary-based, and is built around
IEqualityComparer<TKey>, not IComparer<TKey> - via GetKeyForItem.
If you want to sort it, perhaps just copy the values out?
Jon Slaughter - 18 Mar 2008 00:25 GMT
> Why not just use a SortedList<TKey,TValue>?
>
> KeyedCollection<TKey,TValue> is dictionary-based, and is built around
> IEqualityComparer<TKey>, not IComparer<TKey> - via GetKeyForItem.
>
> If you want to sort it, perhaps just copy the values out?
Its a bit faster than the sorted lists and dictionaries(says O(1) and almost
O(1))
I used a comparer to do it and it seems to work fine. Was hoping there was
something a bit more easier but I guess not.
I need to sort the list based on a string key but have fast access.
SortedList is O(logn) for indexing while keyedcollection is O(1). Since I
don't need to have a "continuous" sort I think just using the comparer will
work fine.