VOOZH about

URL: https://www.geeksforgeeks.org/c-sharp/stack-synchronized-method-in-c-sharp/

⇱ Stack.Synchronized() Method in C# - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Stack.Synchronized() Method in C#

Last Updated : 11 Jul, 2025
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:
Runtime Error:
Unhandled Exception: System.ArgumentNullException: Value cannot be null. Parameter name: stack
Reference:
Comment

Explore