IsFixedSize, IsReadOnly. The Array type provides several properties. Some of these help us detect features. These include IsFixedSize, IsReadOnly and IsSynchronized.
Property notes. These properties are defined on the IList and ICollection interfaces. IList requires IsFixedSize and IsReadOnly, and ICollection requires IsSynchronized.
In this code example, we see 3 parts. First we see the C# program that uses the 3 properties. Next we see the output of the program, and the property implementations.
Info You can see that the IsFixedSize, IsReadOnly, and IsSynchronized properties all return a constant boolean.
using System;
class Program
{
static void Main()
{
int[] array = new int[4];
Console.WriteLine(array.IsFixedSize);
Console.WriteLine(array.IsReadOnly);
Console.WriteLine(array.IsSynchronized);
}
}True
False
Falsepublic bool IsFixedSize
{
get
{
return true;
}
}
public bool IsReadOnly
{
get
{
return false;
}
}
public bool IsSynchronized
{
get
{
return false;
}
}
IList, ICollection. If you have a variable reference of type IList or ICollection, these properties may be useful. These properties help with the interfaces an array implements.
A summary. We looked at the IsFixedSize, IsReadOnly, and IsSynchronized properties. If you know you are dealing with an array, these properties are never useful—they are constant.
Dot Net Perls is a collection of pages with code examples, which are updated to stay current. Programming is an art, and it can be learned from examples.
Donate to this site to help offset the costs of running the server. Sites like this will cease to exist if there is no financial support for them.
Sam Allen is passionate about computer languages, and he maintains 100% of the material available on this website. He hopes it makes the world a nicer place.
This page was last updated on Mar 3, 2022 (edit link).