What does Array.IsReadOnly property of array class do in C#?

CsharpProgrammingServer Side Programming

The Array.IsReadOnly property gets a value indicating whether the Array is read-only.

Firstly, set the array values −

Array arr = Array.CreateInstance(typeof(String), 3);
arr.SetValue("Electronics", 0);
arr.SetValue("Clothing", 1);

Now let’s use the IsReadOnly property to find whether the Array is read-only. If the array is read-only, then it cannot be updated −

arr.IsReadOnly

The following is the complete example stating the usage of Array.IsReadOnly property −

Example

 Live Demo

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace lower {
   class Program {
      static void Main(string[] args) {
         Array arr = Array.CreateInstance(typeof(String), 3);
         arr.SetValue("Electronics", 0);
         arr.SetValue("Clothing", 1);

         Console.WriteLine("Lower Bound: {0}",arr.GetLowerBound(0).ToString());
         Console.WriteLine("isReadOnly: {0}",arr.IsReadOnly.ToString());

         Console.ReadLine();
      }
   }
}

Output

Lower Bound: 0
isReadOnly: False
raja
Published on 08-Aug-2018 08:56:39
Advertisements