TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

C# Array IsFixedSize, IsReadOnly and IsSynchronized

This C# article shows 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?

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.

C# program that 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;
    }
}

You can see that the IsFixedSize, IsReadOnly, and IsSynchronized properties all return a constant boolean. 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 Type: If True, FalseFalse

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.

Interfaces Types, IEnumerable


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf