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:
// 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)); } } |
True
Example 2:
// 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)); } } |
False True
Recommended Posts:
- Difference between Method Overriding and Method Hiding in C#
- C# | Math.Abs() Method | Set - 2
- C# | PadRight() Method
- C# | Copy() Method
- C# | Math.Abs() Method | Set - 1
- C# | Math.Exp() Method
- C# | Uri.IsWellFormedOriginalString() Method
- Extension Method in C#
- C# | Uri.ToString() Method
- C# | Method Overriding
- Decimal.Add() Method in C#
- C# | Uri.FromHex() Method
- C# | Uri.IsHexDigit() Method
- C# | Uri.IsBaseOf(Uri) Method
- C# | IsNullOrEmpty() Method
- Stack.Contains() Method in C#
- C# | CompareOrdinal() Method
- C# | Join() Method | Set - 1
- C# | Random.Next() Method
- Stack.Pop() Method 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 contribute@geeksforgeeks.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.

