What does Array.IsFixedSize property of array class do in C# ?

The IsFixedSize property of the ArrayList class is used to determine whether an ArrayList has a fixed size. When IsFixedSize returns true, you cannot add or remove elements, but you can still modify existing elements. When it returns false, the ArrayList can grow or shrink dynamically.

Regular ArrayLists created with the default constructor always return false for IsFixedSize because they can dynamically resize. However, you can create fixed-size wrappers using ArrayList.FixedSize() method.

Syntax

Following is the syntax to check the IsFixedSize property −

bool isFixed = arrayList.IsFixedSize;

Following is the syntax to create a fixed-size ArrayList wrapper −

ArrayList fixedList = ArrayList.FixedSize(originalList);

Return Value

The IsFixedSize property returns a bool value −

  • true if the ArrayList has a fixed size

  • false if the ArrayList can dynamically resize

Using IsFixedSize with Regular ArrayList

Example

using System;
using System.Collections;

class Demo {
   public static void Main() {
      ArrayList arrList = new ArrayList();

      Console.WriteLine("Adding some numbers:");
      arrList.Add(45);
      arrList.Add(78);

      Console.WriteLine("Count: " + arrList.Count);
      Console.WriteLine("IsFixedSize: " + arrList.IsFixedSize);

      // Can add more elements since it's not fixed size
      arrList.Add(99);
      Console.WriteLine("After adding another element, Count: " + arrList.Count);
   }
}

The output of the above code is −

Adding some numbers:
Count: 2
IsFixedSize: False
After adding another element, Count: 3

Using ArrayList.FixedSize() Method

Example

using System;
using System.Collections;

class Demo {
   public static void Main() {
      // Create a regular ArrayList
      ArrayList originalList = new ArrayList();
      originalList.Add(10);
      originalList.Add(20);
      originalList.Add(30);

      // Create a fixed-size wrapper
      ArrayList fixedList = ArrayList.FixedSize(originalList);

      Console.WriteLine("Original ArrayList IsFixedSize: " + originalList.IsFixedSize);
      Console.WriteLine("Fixed-size wrapper IsFixedSize: " + fixedList.IsFixedSize);

      // Modify existing element (allowed)
      fixedList[0] = 100;
      Console.WriteLine("Modified first element to: " + fixedList[0]);

      // Try to add new element (this would throw exception)
      Console.WriteLine("Count in fixed list: " + fixedList.Count);
   }
}

The output of the above code is −

Original ArrayList IsFixedSize: False
Fixed-size wrapper IsFixedSize: True
Modified first element to: 100
Count in fixed list: 3

Comparison of ArrayList Types

ArrayList Type IsFixedSize Can Add/Remove Can Modify Elements
Regular ArrayList False Yes Yes
Fixed-size wrapper True No Yes
Read-only wrapper True No No

Conclusion

The IsFixedSize property indicates whether an ArrayList can change its size. Regular ArrayLists return false and allow dynamic resizing, while fixed-size wrappers created with ArrayList.FixedSize() return true and prevent adding or removing elements but still allow modification of existing elements.

Updated on: 2026-03-17T07:04:35+05:30

345 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements