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.
- Synchronization of an object is done so that only one thread can manipulate the data in the array.
- A property is a member of a class that provides a means for reading, writing and computing private data fields.
- Array.SyncRoot Property implements the System.Collections.ICollection interface.
- The synchronizing code cannot directly perform on the collection, so it must perform operations on the SyncRoot of the collection in order to guarantee the proper operation of collections that are derived from other objects.
- Retrieving the value of this property is an O(1) operation.
Property Value: An object that can be used to synchronize access to the Array.
Example 1: In this code, we are using SyncRoot to get Synchronized access to the Array named arr, which is not a thread-safe procedure and can cause an exception. So to avoid the exception we lock the collection during the enumeration.
12 15 20 3 6
Example 2: In the below example we use SynRoot property with an array of objects of class X.
0 0 0 0 0
- How to get Synchronize access to the StringDictionary in C#
- How to get Synchronize access to the StringCollection in C#
- How to get Synchronize access to the ListDictionary in C#
- How to get Synchronize access to the Stack in C#
- C# | How to get Synchronize access to the ArrayList
- How to get Synchronize access to the HybridDictionary in C#
- How to get Synchronize access to the Queue in C#
- How to access an associative array by integer index in PHP?
- Access Modifiers in C#
- How to access structure elements using Pointers in C#
- How to Access Interface Fields in Golang?
- access command in linux with examples
- How to Access All Users in Linux Using Different Commands?
- HTTP headers | Access-Control-Max-Age
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.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.
Improved By : ManasiKirloskar