Posts

Showing posts with the label #C# #SortedList

C# - SortedList

The   SortedList<TKey, TValue> , and   SortedList   are collection classes that can store key-value pairs that are sorted by the keys based on the associated   IComparer   implementation. For example, if the keys are of primitive types, then sorted in ascending order of keys. C# supports generic and non-generic  SortedList . It is recommended to use generic  SortedList<TKey, TValue>  because it performs faster and less error-prone than the non-generic  SortedList . SortedList Characteristics SortedList<TKey, TValue>  is an array of key-value pairs sorted by keys. Sorts elements as soon as they are added. Sorts primitive type keys in ascending order and object keys based on  IComparer<T> . Comes under  System.Collection.Generic  namespace. A key must be unique and cannot be null. A value can be null or duplicate. A value can be accessed by passing associated key in the indexer  mySortedList[key]...