Open In App
Related Articles

C# | Check if a SortedList is read-only

Improve Article
Save Article
Like Article

SortedList class is a collection of (key, value) pairs which 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.Collections namespace.
SortedList.IsReadOnly property is used to get a value which indicates that a SortedList object is read-only or not.

Properties of SortedList:

  • Internally the object of SortedList maintain the two arrays. The first array is used to store the elements of the list i.e. keys and the second one is used to store the associated values.
  • A key cannot be null but value can be.
  • As SortedList used sorting which makes it slower in comparison to Hashtable.
  • The capacity of a SortedList can be dynamically increased through reallocation.
  • The keys in the SortedList cannot be duplicated but values can be.
  • The SortedList can be sorted according to the keys using the IComparer(Either in ascending or descending order).


public virtual bool IsReadOnly { get; }

Return Value: This property returns True if the SortedList object is read-only, otherwise it returns False. The default is False.


// C# code to check if a
// SortedList is read-only
using System;
using System.Collections;
class GFG {
    // Driver code
    public static void Main()
        // Creating an SortedList
        SortedList mySortedList = new SortedList();
        // Adding elements to SortedList
        mySortedList.Add("a", "A");
        mySortedList.Add("b", "B");
        mySortedList.Add("c", "C");
        mySortedList.Add("d", "D");
        // Checking if the created
        // SortedList is read-only or not




  • A collection that is read-only does not allow the addition, removal, or modification of elements after the collection is created.
  • Retrieving the value of this property is an O(1) operation.


Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 01 Feb, 2019
Like Article
Save Article
Similar Reads