IsFixedSize
, IsReadOnly
The Array type provides several properties. Some of these help us detect features. These include IsFixedSize
, IsReadOnly
and IsSynchronized
.
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.
IsFixedSize
, IsReadOnly
, and IsSynchronized
properties all return a constant boolean.IsFixedSize
, IsReadOnly
, or IsSynchronized
on an array type variable.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.
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.