Stack.Equals() Method in C# Last Updated : 28 Jan, 2019 Comments Improve Suggest changes Like Article Like Report Equals(Object) Method which is inherited from the Object class is used to check if a specified Stack class object is equal to another Stack class object or not. This method comes under the System.Collections namespace. Syntax: public virtual bool Equals (object obj); Here, obj is the object which is to be compared with the current object. Return Value: This method return true if the specified object is equal to the current object otherwise it returns false. Below programs illustrate the use of the above-discussed method: Example 1: csharp // C# code to check if two Stack // class objects are equal or not using System; using System.Collections; class GFG { // Driver code public static void Main() { // Creating a Stack named st1 Stack st1 = new Stack(); // Adding elements to st1 st1.Push(1); st1.Push(2); st1.Push(3); st1.Push(4); // Checking whether st1 is // equal to itself or not Console.WriteLine(st1.Equals(st1)); } } Output: True Example 2: csharp // C# code to check if two Stack // class objects are equal or not using System; using System.Collections; class GFG { // Driver code public static void Main() { // Creating a Stack named st1 Stack st1 = new Stack(); // Adding elements to the Stack st1.Push("C"); st1.Push("C++"); st1.Push("Java"); st1.Push("C#"); // Creating a Stack named st2 Stack st2 = new Stack(); st2.Push("HTML"); st2.Push("CSS"); st2.Push("PHP"); st2.Push("SQL"); // Checking whether st1 is // equal to st2 or not Console.WriteLine(st1.Equals(st2)); // Creating a new Stack Stack st3 = new Stack(); // Assigning st2 to st3 st3 = st2; // Checking whether st3 is // equal to st2 or not Console.WriteLine(st3.Equals(st2)); } } Output: False True Comment More infoAdvertise with us K Kirti_Mangal Follow Improve Article Tags : C# CSharp-method CSharp-Collections-Namespace CSharp-Collections-Stack Similar Reads C# Stack Class In C#, the Stack<T> class represents a Last-in-First-out (LIFO) collection of objects. The stack is the part of the System.Collections.Generic namespace. This class allows us to push elements onto the stack, pop elements from the stack, and peek at the top element without removing it.The capac 5 min read C# | How to create a Stack Stack() constructor is used to initialize a new instance of the Stack class which will be empty and will have the default initial capacity. Stack represents a last-in, first out collection of object. It is used when you need last-in, first-out access to items. When you add an item in the list, it is 2 min read Stack.Count Property in C# This method(comes under System.Collections namespace) is used to get the number of elements contained in the Stack. The capacity is the number of elements that the Stack can store and the count is the number of elements that are actually in the Stack. The capacity is always greater than or equal to 2 min read Stack.IsSynchronized Property in C# This method(comes under System.Collections namespace) is used to get a value indicating whether access to the Stack is synchronized (thread safe) or not. To guarantee the thread safety of the Stack, all operations must be done through the wrapper returned by the Synchronized method. Also, retrieving 2 min read How to get Synchronize access to the Stack in C# Stack.SyncRoot Property is used to get an object which can be used to synchronize access to the Stack. Stack represents last-in, first out collection of object. It is used when you need last-in, first-out access to items. When you add an item in the list, it is called pushing the item and when you r 3 min read Stack.Clear Method in C# This method(comes under System.Collections namespace) is used to remove all the objects from the Stack. This method will set the Count of Stack to zero, and references to other objects from elements of the collection are also removed. This method is an O(n) operation, where n is Count. Syntax: publi 2 min read Stack.Clone() Method in C# This method is used to create a shallow copy of the Stack. It just creates a copy of the Stack. The copy will have a reference to a clone of the internal data array but not a reference to the original internal data array. Syntax: public virtual object Clone (); Return Value: The method returns an Ob 2 min read Stack.Contains() Method in C# This method(comes under System.Collections namespace) is used to check whether a specified element is present is Stack or not. Internally this method checks for equality by calling the Object.Equals method. Also, it performs a linear search, therefore, this method is an O(n) operation, where n is Co 2 min read Stack.CopyTo() Method in C# This method(comes under System.Collections namespace) is used to copy the Stack to an existing 1-D Array which starts from the specified array index. The elements are copied onto the array in last-in-first-out (LIFO) order, similar to the order of the elements returned by a succession of calls to Po 2 min read Stack.Equals() Method in C# Equals(Object) Method which is inherited from the Object class is used to check if a specified Stack class object is equal to another Stack class object or not. This method comes under the System.Collections namespace. Syntax: public virtual bool Equals (object obj); Here, obj is the object which is 2 min read Like