Home
Map
Array IsFixedSize, IsReadOnly and IsSynchronizedUse the IsFixedSize, IsReadOnly and IsSynchronized array properties.
C#
This page was last reviewed on Mar 3, 2022.
IsFixedSize, IsReadOnly. The Array type provides several properties. Some of these help us detect features. These include IsFixedSize, IsReadOnly and IsSynchronized.
Array
Property notes. These properties are defined on the IList and ICollection interfaces. IList requires IsFixedSize and IsReadOnly, and ICollection requires IsSynchronized.
IList
Property
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.
true, false
And These are defined in the Array type, which means all arrays will return these values.
So There is no point of ever calling IsFixedSize, IsReadOnly, or IsSynchronized on an array type variable.
bool
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 False
public 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.
interface
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 tested code examples. Pages are continually updated to stay current, with code correctness a top priority.
Sam Allen is passionate about computer languages. In the past, his work has been recommended by Apple and Microsoft and he has studied computers at a selective university in the United States.
This page was last updated on Mar 3, 2022 (edit link).
Home
Changes
© 2007-2024 Sam Allen.