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# −
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); } } }
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