Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does sorted list have to have a key value pair?

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)

like image 755
ChrisAU Avatar asked Mar 15 '10 12:03

ChrisAU


People also ask

Does sorted list allow duplicate keys?

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.

In what way sorted list will add the values?

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.

Which collection type represents a collection of key and value pairs that are sorted by keys and are accessible by keys and values?

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.

What is sorted list in C#?

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.


1 Answers

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).

like image 134
Konrad Rudolph Avatar answered Sep 19 '22 08:09

Konrad Rudolph