The capacity property in SortedList class has the maximum size of the SortedList.
The default capacity of a SortedList is 16.
You can try to run the following the code to implement Capacity property of SortedList class in C# −
Example
using System;
using System.Collections;
namespace Demo {
class Program {
static void Main(string[] args) {
SortedList s = new SortedList();
s.Add("S1", "Maths");
s.Add("S2", "Science");
s.Add("S3", "English");
s.Add("S4", "Economics");
Console.WriteLine("Capacity = " + s.Capacity);
}
}
}Output
Capacity = 16
Above we first added elements to the SortedList.
SortedList s = new SortedList();
s.Add("S1", "Maths");
s.Add("S2", "Science");
s.Add("S3", "English");
s.Add("S4", "Economics");Then we found out the capacity −
s.Capacity