C# Array SyncRoot
Description
Array SyncRoot
gets an object that can be used to synchronize
access to the Array.
Syntax
Array.SyncRoot
has the following syntax.
public Object SyncRoot { get; }
Example
The following code example shows how to lock an array during the entire enumeration by using the SyncRoot property.
using System;/* w w w . j av a2 s.c o m*/
public class MainClass{
public static void Main(String[] argv){
Array myArray = new int[] { 1, 2, 4 };
lock(myArray.SyncRoot)
{
foreach (Object item in myArray)
Console.WriteLine(item);
}
}
}
The code above generates the following result.