
- 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
Synchronization of ArrayList in C#
Use the ArrayList.Synchronized Method in C# for synchronization of ArrayList in C#.
Let us see an example to lock the collection using SyncRoot property in C# −
ArrayList arr = new ArrayList(); lock(arr.SyncRoot) { foreach (object ele in arr) { } }
The following is the complete example to check the synchronization status of ArrayList −
Example
using System; using System.Collections; public class Demo { public static void Main() { ArrayList arr1 = new ArrayList(); arr1.Add("One"); arr1.Add("Two"); arr1.Add("Three"); arr1.Add("Four"); arr1.Add("Five"); arr1.Add("Six"); arr1.Add("Seven"); arr1.Add("Eight"); // set synchronized wrapper around the ArrayList ArrayList arr2 = ArrayList.Synchronized(arr1); // sychronization status of first ArrayList Console.WriteLine("arr1 = {0}", arr1.IsSynchronized ? " synchronized" : "not synchronized"); // sychronization status of second ArrayList Console.WriteLine("arr2 = {0}", arr2.IsSynchronized ? "synchronized" : "not synchronized"); } }
Output
arr1 = not synchronized arr2 = synchronized
- Related Articles
- Hardware Synchronization
- Process Synchronization in Linux
- Process Synchronization in Windows
- Process Synchronization in Solaris
- Thread Synchronization in C#
- Channel synchronization in Golang
- Synchronization of Alternators by Synchroscope
- Synchronization and Pooling of processes in Python
- Synchronization and Pooling of processes in C#
- Process Synchronization in C/C++
- Method and Block Synchronization in Java
- Threads and Thread Synchronization in C#
- Synchronization of Alternators by Synchronizing Lamps Method
- Print numbers in sequence using thread synchronization
- Print numbers in sequence using thread synchronization in C Program.

Advertisements