C# | Check if an Array has fixed size or not

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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);
    }
}
}

chevron_right


Output:

Topic of C#:
Array,  
String,  
Stack,  
Queue,  
Exception,  
Operators 

Result: True

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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);
    }
}
}

chevron_right


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:



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.