
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
Stack Class in C#
Stack class represents a last-in, first out collection of object. It is used when you need a last-in, first-out access of items.
The following is the property of Stack class −
Count − Gets the number of elements in the stack.
The following are the methods of Stack class −
Sr.No. | Method & Description |
---|---|
1 | public virtual void Clear(); Removes all elements from the Stack. |
2 | public virtual bool Contains(object obj); Determines whether an element is in the Stack. |
3 | public virtual object Peek(); Returns the object at the top of the Stack without removing it. |
4 | public virtual object Pop(); Removes and returns the object at the top of the Stack. |
5 | public virtual void Push(object obj); Inserts an object at the top of the Stack. |
6 | public virtual object[] ToArray(); Copies the Stack to a new array. |
- Related Articles
- The Stack Class in Javascript
- What is the Stack class in C#?
- How to use Stack class in C#?
- Push vs pop in stack class in C#
- What is the Count property of Stack class in C#?
- Stack and the stack pointer in 8085 Microprocessor
- stack empty() and stack size() in C++ STL
- Stack in Java
- Stack in Java Programming
- Stack Unwinding in C++
- Min Stack in Python
- Find maximum in stack in O(1) without using additional stack in C++
- Which is in More Demand: Java Full Stack or Python Full Stack
- Print stack trace in Java
- Stack ADT in Data Structures

Advertisements