This method(comes under
System.Collections Namespace) is used to return a synchronized (thread safe) wrapper for the Stack. To guarantee the thread safety of the Stack, all operations must be done through this wrapper.
Syntax:
public static System.Collections.Stack Synchronized (System.Collections.Stack stack);
Return Value: It returns synchronized wrapper around the Stack.
Exception: This method will give
ArgumentNullException if the
stack is null.
Below programs illustrate the use of above-discussed method:
Example 1:
Output:
myStack is Not Synchronized.
st is Synchronized.
Example 2: