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 has a fixed size or not.

Properties of SortedList:

  • Internally the object of SortedList maintain 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 uses sorting, it 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 IsFixedSize { get; }

Return Value: This property returns True if the SortedList object has a fixed size, otherwise it returns False. The default value of this property is False.

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# code to check if a SortedList
// object has a fixed size
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("1", "one");
        mySortedList.Add("2", "two");
        mySortedList.Add("3", "three");
        mySortedList.Add("4", "four");
        mySortedList.Add("5", "five");
  
        // Checking if a SortedList
        // object has a fixed size
        Console.WriteLine(mySortedList.IsFixedSize);
    }
}

chevron_right


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.


My Personal Notes arrow_drop_up

In love with a semicolon because sometimes i miss it so badly)

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.