Last Updated : 11 Jul, 2025
SortedList class is a collection of
(key, value) pairswhich are sorted according to keys. Those pairs can be accessible by key and as well as by index(zero-based indexing). This comes under
System.Collectionsnamespace.
Properties of SortedList:Below programs illustrate how to create a SortedList:
Example 1: CSharp
// C# Program to illustrate how
// to create a SortedList
using System;
using System.Collections;
class Geeks {
// Main Method
public static void Main(String[] args)
{
// Creating object of SortedList
// fslist is the SortedList object
SortedList fslist = new SortedList();
// Count property is used to get the
// number of key/value pairs in fslist
// It will give 0 as no pairs are present
Console.WriteLine(fslist.Count);
}
}
Output:
0Example 2: CSharp
// C# Program to illustrate how
// to create a SortedList
using System;
using System.Collections;
class Geeks {
// Main Method
public static void Main(String[] args)
{
// Creating object of SortedList
// fslist is the SortedList object
SortedList fslist = new SortedList();
// Count property is used to get the
// number of key/value pairs in fslist
// It will give 0 as no pairs are present
Console.WriteLine(fslist.Count);
// Adding key/value pairs in fslist
fslist.Add("1", "GFG");
fslist.Add("2", "Geeks");
fslist.Add("3", "for");
fslist.Add("4", "Geeks");
// Count property is used to get the
// number of key/value pairs in fslist
// It will give output 4
Console.WriteLine(fslist.Count);
}
}
Output:
0 4Reference:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4