C# | Check if an Array has fixed size or not
Last Updated :
01 Feb, 2019
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:
using System;
namespace geeksforgeeks {
class GFG {
public static void Main()
{
string [] topic;
topic = new string [] { "Array, " , "String, " ,
"Stack, " , "Queue, " ,
"Exception, " , "Operators" };
Console.WriteLine( "Topic of C#:" );
foreach ( string ele in topic)
Console.WriteLine(ele + " " );
Console.WriteLine();
Console.WriteLine( "Result: " + topic.IsFixedSize);
}
}
}
|
Output:
Topic of C#:
Array,
String,
Stack,
Queue,
Exception,
Operators
Result: True
Example 2:
using System;
namespace geeksforgeeks {
class GFG {
public static void Main()
{
string [] str = new string [] { null };
Console.WriteLine( "Result: " + str.IsFixedSize);
}
}
}
|
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:
Share your thoughts in the comments
Please Login to comment...