HomeSearch

C# IsFixedSize, IsReadOnly and IsSynchronized Arrays

Use the IsFixedSize, IsReadOnly and IsSynchronized array properties.
IsFixedSize, IsReadOnly. The Array type provides several properties. Some of these help us detect features. These include IsFixedSize, IsReadOnly and IsSynchronized. What do these properties do and why are they there?Array
Example. In the following block, we see three parts. First we see the C# program that uses the three properties. Next we see the output of the program. And finally we see the implementation of the properties in the .NET Framework.

Return: 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 really no point of ever calling IsFixedSize, IsReadOnly, or IsSynchronized on an array type variable.

Bool
C# program that uses these properties using System; class Program { static void Main() { int[] array = new int[4]; Console.WriteLine(array.IsFixedSize); Console.WriteLine(array.IsReadOnly); Console.WriteLine(array.IsSynchronized); } } Output True False False Implementation of properties: .NET Framework public bool IsFixedSize { get { return true; } } public bool IsReadOnly { get { return false; } } public bool IsSynchronized { get { return false; } }
Why are they there? These properties are defined on the IList and ICollection interfaces. With IList, you are required to define IsFixedSize and IsReadOnly. With ICollection, you are required to have IsSynchronized.

Therefore: If you have a variable reference of type IList or ICollection, these properties may be useful.

Summary. In this program, we looked at the IsFixedSize, IsReadOnly, and IsSynchronized properties on the Array type. If you know you are dealing with an array, these properties are never useful as they are constant.

Tip: If you are dealing with one of the interfaces an array implements, they may be more useful.

Interface
© 2007-2019 Sam Allen. Every person is special and unique. Send bug reports to info@dotnetperls.com.
Home
Dot Net Perls