C# ArrayList SyncRoot
Description
ArrayList SyncRoot
gets an object that can be used to synchronize
access to the ArrayList.
Syntax
ArrayList.SyncRoot
has the following syntax.
public virtual Object SyncRoot { get; }
Example
The following code example shows how to lock the collection using the SyncRoot during the entire enumeration.
using System.Collections;
using System;//from ww w .j av a 2s . com
public class MainClass{
public static void Main(String[] argv){
ArrayList myCollection = new ArrayList();
lock(myCollection.SyncRoot)
{
foreach (object item in myCollection)
{
// Insert your code here.
}
}
}
}
The code above generates the following result.