C# SortedList SyncRoot

Description

SortedList SyncRoot gets an object that can be used to synchronize access to a SortedList object.

Syntax

SortedList.SyncRoot has the following syntax.


public virtual Object SyncRoot { get; }

Example

The following code example shows how to lock the collection using the SyncRoot property during the entire enumeration.


using System.Collections;
using System;/*w  ww.  j a v  a  2 s .  c  o m*/
public class MainClass{
  public static void Main(String[] argv){  
    SortedList myCollection = new SortedList();
    lock(myCollection.SyncRoot)
    {
        foreach (object item in myCollection)
        {
            // Insert your code here.
        }
    }
  }
}
    

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Collections »




ArrayList
BitArray
Comparer
Hashtable
Queue
SortedList
Stack