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 Queue
- C# | Check if a HashSet contains the specified element
- C# | How to check whether a List contains a 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
- C# | Stack Class
- C# Stack with Examples
- Stack.Pop() Method in C#
- Stack.Contains() Method in C#
- C# | How to create a Stack
- Implementing Stack in C#
- Stack.GetEnumerator Method 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 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.