ArrayList.IsSynchronized Property is used to get a value which indicate whether access to the ArrayList is synchronized (thread safe).
Syntax:
public virtual bool IsSynchronized { get; }
Return Value: This property returns the true if access to the ArrayList is synchronized (thread safe) otherwise it returns false. The default is false.
Below programs illustrate the use of above-discussed property:
Example 1:
// C# code to check if ArrayList // Is Synchronized or not using System; using System.Collections; class GFG { // Driver code public static void Main() { // Creating an ArrayList ArrayList myList = new ArrayList(); // Adding elements to ArrayList myList.Add("A"); myList.Add("B"); myList.Add("C"); myList.Add("D"); myList.Add("E"); myList.Add("F"); // Creates a synchronized // wrapper around the ArrayList ArrayList smyList = ArrayList.Synchronized(myList); // Displays the synchronization // status of both ArrayList Console.WriteLine("myList is {0}.", myList.IsSynchronized ? "Synchronized" : "Not Synchronized"); Console.WriteLine("smyList is {0}.", smyList.IsSynchronized ? "Synchronized" : "Not Synchronized"); } } |
myList is Not Synchronized. smyList is Synchronized.
Example 2:
// C# code to check if ArrayList // Is Synchronized or not using System; using System.Collections; class GFG { // Driver code public static void Main() { // Creating an ArrayList ArrayList myList = new ArrayList(); // Adding elements to ArrayList myList.Add(1); myList.Add(2); myList.Add(3); myList.Add(4); myList.Add(5); myList.Add(5); // the default is false for // IsSynchronized property Console.WriteLine(myList.IsSynchronized); } } |
False
Note:
- Retrieving the value of this property is an O(1) operation.
- To guarantee the thread safety of the ArrayList, all operations must be done through the wrapper returned by the Synchronized method.
- Enumerating through a collection is intrinsically not a thread-safe procedure. Even when a collection is synchronized, other threads can still modify the collection, which causes the enumerator to throw an exception.
Reference:
Recommended Posts:
- C# | Creating a synchronized (thread-safe) wrapper for the ArrayList
- C# | Check if ListDictionary is synchronized (thread safe)
- C# | Check if Hashtable is synchronized (thread safe)
- C# | Check if an array is synchronized (thread safe) or not
- C# | Check if the BitArray is synchronized (thread safe)
- C# | Check if HybridDictionary is Synchronized (thread safe)
- C# | Check if StringCollection is synchronized (thread safe)
- C# | Check if StringDictionary is synchronized (thread safe)
- C# | Creating a synchronized (thread-safe) wrapper for the Hashtable
- C# | Creating a synchronized (thread-safe) wrapper for a SortedList object
- C# | Check if a thread belongs to managed thread pool or not
- How to check whether a thread is a background thread or not in C#
- C# | Check if a SortedList object is synchronized
- How to check whether a thread is alive or not in C#
- C# | How to check current state of a thread
- C# | Check if the ArrayList is read-only
- C# | Check if two ArrayList objects are equal
- C# | Check if the ArrayList has a fixed size
- C# | Check whether an element is contained in the ArrayList
- Naming a thread and fetching name of current thread in C#
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

