C# SortedList Examples – Programming, Pseudocode Example, C# Programming Example
C# C# Console

C# SortedList Examples

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.

Example 1:


Example 2: SortedList.Add() method adds items to the collection. The following code snippet adds several items to the colleciton. 


Example 3: In the following example, we add an element with the number 7, so is the capacity is 8; if we add 9th elements, the capacity will be 16 (double the previous one).

Example 4:

The Count property counts the number of elements in the SortedList or we can say that Count gets the number of key/value pairs contained in the SortedList<TKey, TValue>. For example:


Example 5:


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: