C# | Creating a synchronized (thread-safe) wrapper for the ArrayList Last Updated : 01 Feb, 2019 Comments Improve Suggest changes Like Article Like Report Synchronized(ArrayList) method is used to get an ArrayList wrapper that is synchronized (thread safe). Syntax: public static System.Collections.ArrayList Synchronized (System.Collections.ArrayList list); Here, the list is the ArrayList which is to be synchronized. Return Value: It returns an ArrayList wrapper which is synchronized (thread safe). Exception: This method throws ArgumentNullException if the list is null. Below programs illustrate the use of above-discussed method: Example 1: CSharp // 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("Geeks"); myList.Add("for"); myList.Add("Geeks"); myList.Add("Noida"); myList.Add("Geeks Classes"); myList.Add("Delhi"); // 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"); } } Output: myList is Not Synchronized. smyList is Synchronized. Example 2: CSharp // 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("Geeks"); myList.Add("for"); myList.Add("Geeks"); myList.Add("Noida"); myList.Add("Geeks Classes"); myList.Add("Delhi"); // it will give error as // the parameter is null ArrayList smyList = ArrayList.Synchronized(null); } } Runtime Error: Unhandled Exception: System.ArgumentNullException: Value cannot be null. Parameter name: list Note: For the thread safety of the ArrayList, all operations must be done through this wrapper. Reference: https://docs.microsoft.com/en-us/dotnet/api/system.collections.arraylist.synchronized?view=netframework-4.7.2#System_Collections_ArrayList_Synchronized_System_Collections_ArrayList_ Comment More infoAdvertise with us Next Article C# | Creating a synchronized (thread-safe) wrapper for the ArrayList K Kirti_Mangal Follow Improve Article Tags : C# CSharp-method CSharp-Collections-Namespace CSharp-Collections-ArrayList Similar Reads C# | Creating a synchronized (thread-safe) wrapper for the Hashtable Hashtable.Synchronized(Hashtable) Method is used to return a synchronized (thread-safe) wrapper for the Hashtable.Syntax: public static System.Collections.Hashtable Synchronized (System.Collections.Hashtable table); Here table is the Hashtable which is to be synchronized.Return Value: This method re 2 min read C# | Creating a synchronized (thread-safe) wrapper for a SortedList object SortedList.Synchronized(SortedList) Method is used to get the synchronized (thread-safe) wrapper for a SortedList object. Syntax: public static System.Collections.SortedList Synchronized (System.Collections.SortedList list); Here, list is the name of the SortedList object which is to be synchronized 2 min read C# | Creating a read-only wrapper for the ArrayList ArrayList.ReadOnly(ArrayList) Method is used to get a read-only ArrayList wrapper. Syntax: public static System.Collections.ArrayList ReadOnly(System.Collections.ArrayList list); Here, the list is the ArrayList which is to be wrapped. Return Value: It returns a read-only ArrayList Wrapper around the 2 min read C# | Check if ArrayList is Synchronized (thread safe) 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 i 2 min read C# | Check if an array is synchronized (thread safe) or not Array.IsSynchronized Property is used to get a value which indicates whether access to the Array is synchronized (thread-safe) or not. Syntax: public bool IsSynchronized { get; } Property Value: This property always returns false for all arrays. Below programs illustrate the use of above-discussed p 2 min read C# | Check if the BitArray is synchronized (thread safe) The BitArray class manages a compact array of bit values, which are represented as Booleans, where true indicates that the bit is on i.e, 1 and false indicates the bit is off i.e, 0. This class is contained in System.Collections namespace. BitArray.IsSynchronized property is used to get a value indi 2 min read C# | How to get Synchronize access to the ArrayList ArrayList.SyncRoot Property is used to get an object which can be used to synchronize access to the ArrayList. ArrayList represents an ordered collection of an object that can be indexed individually. It is basically an alternative to an array. It also allows dynamic memory allocation, adding, searc 2 min read How to get Synchronize access to the Array in C# Array.SyncRoot Property is used to get an object that can be used to synchronize access to the Array. An array is a group of like-typed variables that are referred to by a common name. Array class comes under the System namespace. Important Points: Synchronization of an object is done so that only o 3 min read C# | Check if Hashtable is synchronized (thread safe) Hashtable.IsSynchronized Property is used to get a value indicating whether access to the Hashtable is synchronized(thread-safe). Syntax: public virtual bool IsSynchronized { get; } Return Value: This property return true if access to the Hashtable is synchronized (thread-safe), otherwise it returns 2 min read How to get Synchronize access to the Queue in C# Queue.SyncRoot Property is used to get an object which can be used to synchronize access to the Queue. Queue represents a first-in, first out collection of object. It is used when you need first-in, first-out access of items. When you add an item in the list, it is called enqueue, and when you remov 2 min read Like