Last Updated : 11 Jul, 2025
Equals(Object) Methodwhich is inherited from the
Object classis used to check if a specified
Stack classobject 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,
objis the object which is to be compared with the current object.
Return Value:This method return
trueif 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));
}
}
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));
}
}
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4