Home »
.Net »
C# Programs
C# SortedList Class Reference – Properties, Methods, Examples / Programs
SortedList class represents a collection (both generic and non-generic types of collections) of key/value pairs that are sorted by the keys and are accessible by key and by index.
To use SortedList class we need to use the following namespaces:
- System.Collections.Generic
- System.Collections
Now we will discuss some important points regarding SortedList:
- In SortedList, there are two arrays that will be maintained internally, one array is used to store keys and another array is used to maintain values.
- In SortedList, we cannot pass null for key, but we can pass the value as a null.
- Here, we can access SortedList items using a key or using the index.
- SortedList class implements the following interfaces:
- ICollection
- IEnumerable
- ICloneable
- IDictionary
- Duplicate keys are not allowed in SortedList.
- SortedList is used as a generic and non-generic type.
- We can cast key and value pair of SortedList into DictionaryEntry.
Creation of SortedList:
There are 6 different types of constructors are used in SortedList. Here, we need to include two namespaces System.Collections.Generic and System.Collections.
SortedList list = new SortedList();
This section contains the solved C# SortedList Class Reference – Properties, Methods, Examples. Practice these programs to learn the use of various SortedList-related methods/operations, these programs contain the solved code, outputs, and the detailed explanation of the statements, functions used in the C# SortedList Class Reference – Properties, Methods, Examples.
List of C# SortedList Class Reference – Properties, Methods, Examples
- C# - SortedList.Add() Method with Example
- C# - SortedList.Remove() Method with Example
- C# - SortedList.RemoveAt() Method with Example
- C# - SortedList.GetByIndex() Method with Example
- C# - SortedList.GetKey() Method with Example
- C# - SortedList.GetKeyList() Method with Example
- C# - SortedList.GetValueList() Method with Example
- C# - SortedList.IndexOfKey() Method with Example
- C# - SortedList.IndexOfValue() Method with Example
- C# - SortedList.ContainsKey() Method with Example
- C# - SortedList.ContainsValue() Method with Example
- C# - SortedList.Contains() Method with Example
- C# - SortedList.CopyTo() Method with Example
- C# - SortedList.Clone() Method with Example
- C# - SortedList.Clear() Method with Example
- C# - SortedList.Keys Property with Example
- C# - SortedList.Values Property with Example
- C# - SortedList.SetByIndex() Method with Example
- C# - SortedList.Capacity Property with Example