ReadOnly method in ArrayList

In this article I will explain the ReadOnly(ArrayList) method of ArrayList.
  • 2408

Introduction

The ReadOnly(ArrayList) method of ArrayList returns a read-only ArrayList wrapper.We pass the ArrayList in the ReadOnly method and then check that it is readonly or not by using IsReadOnly property of ArrayList,Which returns the result in the form of true and false,if it is readonly then it return true otherwise false.In the following example I use conditional statement.

Example

namespace ConsoleApplication6

{

    class Program

    {

        static void Main(string[] args)

        {

            // Creates a new ArrayList.

            ArrayList days = new ArrayList();

            days.Add("Sunday");

            days.Add("Monday");

            days.Add("Tuesday");

            days.Add("Wednesday");

            // Creates a read-only copy of the ArrayList.

            ArrayList ReadOnly = ArrayList.ReadOnly(days);

            // Displays whether the ArrayList is read-only or writable.

            Console.WriteLine("ArrayList days is {0}.", days.IsReadOnly ? "read-only" : "writable");

            Console.WriteLine("ArrayList ReadOnly is {0}.", ReadOnly.IsReadOnly ? "read-only" : "writable");

        }

    }

}

 

Output

readonly.jpg 

 

Ask Your Question  

Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.