Skip to content
Related Articles

Related Articles

C# | Check if an Array has fixed size or not
  • Last Updated : 01 Feb, 2019
GeeksforGeeks - Summer Carnival Banner

Array.IsFixedSize Property is used to get a get a value indicating whether the Array has a fixed size. This property implements the IList.IsFixedSize Property .

Syntax:

public bool IsFixedSize { get; }

Property Value: This property is always return true for all arrays.

Below programs illustrate the use of above-discussed property:

Example 1:






// C# program to illustrate
// IsFixedSize of Array class
using System;
namespace geeksforgeeks {
  
class GFG {
  
    // Main Method
    public static void Main()
    {
  
        // declares an 1D Array of string
        string[] topic;
  
        // allocating memory for topic.
        topic = new string[] {"Array, ", "String, ",
                               "Stack, ", "Queue, ",
                        "Exception, ", "Operators"};
  
        // Displaying Elements of the array
        Console.WriteLine("Topic of C#:");
  
        foreach(string ele in topic)
            Console.WriteLine(ele + " ");
  
        Console.WriteLine();
  
        // Here we check whether is
        // array of fixed size or not
        Console.WriteLine("Result: " + topic.IsFixedSize);
    }
}
}
Output:
Topic of C#:
Array,  
String,  
Stack,  
Queue,  
Exception,  
Operators 

Result: True

Example 2:




// C# program to illustrate
// IsFixedSize of Array class
using System;
namespace geeksforgeeks {
  
class GFG {
  
    // Main Method
    public static void Main()
    {
  
        // declares a 1D Array of string 
        // and assigning null to it
        string[] str = new string[] {null};
  
        // Here we check whether is
        // array of fixed size or not
        Console.WriteLine("Result: " + str.IsFixedSize);
    }
}
}
Output:
Result: True

Note:

  • Array implements the IsFixedSize property because it is required by the System.Collections.IList interface.
  • An array with a fixed size does not allow the addition or removal of elements after the creation of an array, but modification of existing elements are allowed.
  • Retrieving the value of this property is an O(1) operation.

Reference:

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :