VOOZH about

URL: https://www.geeksforgeeks.org/c-sharp/stack-tostring-method-in-c-sharp-with-examples/

⇱ Stack.ToString() Method in C# with examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Stack.ToString() Method in C# with examples

Last Updated : 11 Jul, 2025
ToString method is inherited from the Object class which is used to get a string that represents the current object. It can also apply on the Stack. It returns a string which represents the current stack object.
Syntax: public virtual string ToString (); Return Value: This method returns a String representation of the collection.
Example 1: In the below program, GetType() method is used to get the type of the current object. It will clarify whether the given Stack object is converted into the string or not.
Output:
The type of st before ToString Method: System.Collections.Stack
After ToString Method: 
Geeks
For
Geeks
To
Welcome
The type of st after ToString Method: System.String
Example 2:
Output:
The type of st before ToString Method: System.Collections.Stack
After ToString Method: 
5
4
3
2
1
The type of st after ToString Method: System.String
Comment

Explore