Stack represents a last-in, first out collection of object.
Stack<T>.Contains(Object) Method is used to check whether an element is in the Stack<T> or not.
public virtual bool Contains(object obj);
Return Value: The function returns True if the element exists in the Stack<T> and returns False if the element doesn’t exist in the Stack.
Below given are some examples to understand the implementation in a better way:
- C# | How to check whether a List contains a specified element
- C# | Check if an element is in the Queue
- C# | Check if a HashSet contains the specified element
- C# | Check if an element is in the Collection<T>
- C# | Check if the SortedSet contains a specific element
- C# | Check whether an element is contained in the ArrayList
- C# | Check if every List element matches the predicate conditions
- Implementing Stack in C#
- C# Stack with Examples
- Stack.Pop() Method in C#
- C# | Stack Class
- C# | How to create a Stack
- Stack.Contains() Method in C#
- C# | Create a Stack from a collection
- Stack.Clear Method in C#
- C# | Copy the Stack to an Array
- Stack.GetEnumerator Method in C#
- C# | Remove all objects from the Stack
- Stack.IsSynchronized Property in C#
- Removing the object from the top of the Stack in C#
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.