Lock a ArrayList in CSharp

Description

The following code shows how to lock a ArrayList.

Example


using System;//from  w w  w.ja v  a 2 s  .  c  o m
using System.Collections;
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.
            Console.WriteLine("changing");
        }
    }
    
  }
}




















Home »
  C# Tutorial »
    Collections »




ArrayList
BitArray
Collection
Comparer
HashSet
Hashtable
LinkedList
List
ListDictionary
OrderedDictionary
Queue
SortedList
SortedSet
Stack
StringCollection
StringDictionary