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# | Check if an element is in the Collection<T>
- C# | Check if an element is in the Queue
- C# | How to check whether a List contains a specified element
- C# | Check if a HashSet contains the specified element
- C# | Check whether an element is contained in the ArrayList
- C# | Check if the SortedSet contains a specific element
- C# | Check if every List element matches the predicate conditions
- C# | Stack Class
- Implementing Stack in C#
- C# | Copy the Stack to an Array
- Stack.Clear Method in C#
- C# | Convert Stack to array
- C# | Create a Stack from a collection
- Stack.Peek Method in C#
- C# | Remove all objects from the Stack
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.