Export (0) Print
Expand All

Stack.SyncRoot Property

Gets an object that can be used to synchronize access to the Stack.

Namespace:  System.Collections
Assembly:  mscorlib (in mscorlib.dll)

public virtual Object SyncRoot { get; }

Property Value

Type: System.Object
An Object that can be used to synchronize access to the Stack.



To create a synchronized version of the Stack, use the Synchronized method. However, derived classes can provide their own synchronized version of the Stack using the SyncRoot property. The synchronizing code must perform operations on the SyncRoot of the Stack, not directly on the Stack. This ensures proper operation of collections that are derived from other objects. Specifically, it maintains proper synchronization with other threads that might be simultaneously modifying the Stack object.



Stack myCollection = new Stack();

    foreach (object item in myCollection)
        // Insert your code here.


.NET Framework


.NET Framework Client Profile

Supported in: 4, 3.5 SP1



Community Additions

© 2014 Microsoft