How to Check if the ArrayList is read-only in C# ?

Published on October 6, 2016 by Senthil Kumar

Filed under C#

Last modified October 6, 2016

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 2.7 (7 votes)

This article have been viewed 17243 times

There are times when you would use the read-only wrapper in order to prevent modifying the ArrayList. We use the ArrayList.ReadOnly method to create such collection.

When doing so , you might want to check if the ArrayList is Read-only or not.

How to Check if the ArrayList is read-only in C# ?

Use the IsReadOnly property defined in the ArrayList object to check this.

using System;
using System.Collections;

namespace ACConsoleApp1
    class Program
        static void Main(string[] args)
            ArrayList movies = new ArrayList(5);
            movies.Add("Robo 2.0");

            // Create a new ReadOnly ArrayLisy
            var readOnlyArrayLisy = ArrayList.ReadOnly(movies);
            // Check if the ArrayList is a ReadOnly

1 Comment

  1. DeveloperPublish Broadcast #3 | Developer Publish
    October 6, 2016 - 2:13 am

Leave a Comment


You might be Interested in these Posts

How to get the AM or PM value from a DateTime object in C# ?

There are times when you might want to get only the string AM or PM from the DateTime object that yo...

C# Program to swap two numbers without using temporary variable

Problem Write a program in Visual CSharp to swap two numbers using temporary variable and display t...

C# Program to print the sum of two numbers

Problem Write a program in C# to add two numbers and display the result in copnsole window. How to...