If I just want a sorted list of just dates, integers, or doubles is it really necessary to have to define a SortedList(of Integer, Integer)?
Seems intriguing to me, but may just be trival. I'd prefer just to use a SortedList(of Integer).
(This question is in relation to the .Net generic collections)
A SortedList does not allow duplicate keys. Operations on a SortedList object tend to be slower than operations on a Hashtable object because of the sorting. Elements in this collection can be accessed using an integer index.
The SortedList<int, string> will store keys of int type and values of string type. The Add() method is used to add a single key-value pair in a SortedList . Keys cannot be null or duplicate. If found, it will throw a run-time exception.
SortedList<TKey,TValue> Class (System.Collections.Generic) Represents a collection of key/value pairs that are sorted by key based on the associated IComparer<T> implementation.
In C#, SortedList is a collection of key/value pairs which are sorted according to keys. By default, this collection sort the key/value pairs in ascending order. It is of both generic and non-generic type of collection. The generic SortedList is defined in System.
The next version of .NET (4.0) will have the SortedSet
class that exactly does what you want. Until then, encapsulating SortedList
gets closest – unless you want to implement an own class to do this, or use external collection libraries (e.g. C5 which has a SortedArray
and a TreeSet
class).
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