C# | Check if a SortedList is read-only Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report 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). 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: CSHARP // 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: 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. Reference: https://learn.microsoft.com/en-us/dotnet/api/system.collections.sortedlist.isreadonly?view=netframework-4.7.2 Comment More infoAdvertise with us Next Article C# | Check if the ArrayList is read-only S Sahil_Bansall Follow Improve Article Tags : C# CSharp-Collections-Namespace CSharp-Collections-SortedList Similar Reads C# | Check if the BitArray is read-only The BitArray class manages a compact array of bit values, which are represented as Booleans, where true indicates that the bit is on i.e, 1 and false indicates the bit is off i.e, 0. This class is contained in System.Collections namespace. BitArray.IsReadOnly property is used to get a value indicati 2 min read C# | Check if the ArrayList is read-only ArrayList represents an ordered collection of an object that can be indexed individually. It is basically an alternative to an array. It also allows dynamic memory allocation, adding, searching and sorting items in the list. ArrayList.IsReadOnly property is used to check whether the ArrayList is rea 2 min read C# | Check if the StringCollection is read-only StringCollection class is a new addition to the .NET Framework class library that represents a collection of strings. StringCollection class is defined in the System.Collections.Specialized namespace. StringCollection.IsReadOnly property is used to get a value indicating whether the StringCollection 1 min read C# | Check if a SortedList object is synchronized 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.IsSynchronized property is used to get a value indicating whether ac 2 min read C# | Check if an array is read-only or not Array.IsReadOnly Property is used to get a value that indicates whether the Array is read-only or not. Syntax: public bool IsReadOnly { get; } Property Value: This property always returns false for all arrays. Below programs illustrate the use of above-discussed property: Example 1: CSharp // C# pro 2 min read C# | Check if a SortedList object has a fixed size 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.IsFixedSize property is used to check whether a SortedList object ha 2 min read Like