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


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

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 20-Jun-2020

68 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements