
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
Check if the ArrayList is read-only in C#
To check if the ArrayList is read-only, the code is as follows −
Example
using System; using System.Collections; public class Demo { public static void Main(String[] args) { ArrayList list1 = new ArrayList(); list1.Add("ABC"); list1.Add("BCD"); list1.Add("CDE"); list1.Add("DEF"); list1.Add("EFG"); list1.Add("GHI"); list1.Add("HIJ"); list1.Add("IJK"); list1.Add("JKL"); list1.Add("KLM"); Console.WriteLine("Elements in ArrayList..."); foreach (string res in list1) { Console.WriteLine(res); } ArrayList list = ArrayList.Synchronized(list1); Console.WriteLine("Is ArrayList synchronized? = "+list.IsSynchronized); ArrayList list2 = ArrayList.FixedSize(list1); Console.WriteLine("Is ArrayList have a fixed size? = "+list2.IsFixedSize); Console.WriteLine("Is the ArrayList read-only? = "+list1.IsReadOnly); } }
Output
This will produce the following output −
Elements in ArrayList... ABC BCD CDE DEF EFG GHI HIJ IJK JKL KLM Is ArrayList synchronized? = True Is ArrayList have a fixed size? = True Is the ArrayList read-only? = False
Example
Let us see another example −
using System; using System.Collections; public class Demo { public static void Main(String[] args) { ArrayList list1 = new ArrayList(); list1.Add("A"); list1.Add("B"); list1.Add("C"); list1.Add("D"); list1.Add("E"); list1.Add("F"); Console.WriteLine("Elements in ArrayList1..."); foreach (string res in list1) { Console.WriteLine(res); } Console.WriteLine("Is ArrayList1 synchronized? = "+list1.IsSynchronized); Console.WriteLine("Is the ArrayList1 read-only? = "+list1.IsReadOnly); ArrayList list2 = new ArrayList(); list2.Add("A"); list2.Add("B"); list2.Add("C"); list2.Add("D"); list2.Add("E"); list2.Add("F"); Console.WriteLine("Elements in ArrayList2..."); foreach (string res in list2) { Console.WriteLine(res); } Console.WriteLine("Is ArrayList synchronized? = "+list2.IsSynchronized); Console.WriteLine("Is the ArrayList2 read-only? = "+list2.IsReadOnly); } }
Output
This will produce the following output −
Elements in ArrayList1... A B C D E F Is ArrayList1 synchronized? = False Is the ArrayList1 read-only? = False Elements in ArrayList2... A B C D E F Is ArrayList synchronized? = False Is the ArrayList2 read-only? = False
- Related Articles
- Check if the StringCollection is read-only in C#
- Check if the BitArray is read-only in C#
- Check if Hashtable is read-only in C#
- Check if ListDictionary is read-only in C#
- C# Check if HybridDictionary is read only
- Check if OrderedDictionary collection is read-only in C#
- Check if a SortedList is read-only in C#
- Check if an array is read-only or not in C#
- How to make Java ArrayList read only?
- Creating a read-only wrapper for the ArrayList in C#
- How to make an ArrayList read only in Java?
- Check if ArrayList is Synchronized (thread safe) in C#
- Check if the ArrayList has a fixed size in C#
- Check if two ArrayList objects are equal in C#
- How to check if ArrayList contains an item in Java?

Advertisements