Open In App

C# | Check if a SortedList is read-only

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:



Syntax:

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.



Example:




// 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
        Console.WriteLine(mySortedList.IsReadOnly);
    }
}

Output:

False

Note:

Reference:

Article Tags :
C#