What is the Capacity property of SortedList class in C#?

CsharpProgrammingServer Side Programming

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

 Live Demo

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
raja
Published on 07-Aug-2018 08:15:23
Advertisements