Last Updated : 11 Jul, 2025
Equals(Object) Methodwhich is inherited from the
Object classis used to check if a specified
Queue classobject is equal to another Queue 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 Queue
// class objects are equal or not
using System;
using System.Collections;
class GFG {
// Driver code
public static void Main()
{
// Creating a Queue named q1
Queue q1 = new Queue();
// Adding elements to q1
q1.Enqueue(1);
q1.Enqueue(2);
q1.Enqueue(3);
q1.Enqueue(4);
// Checking whether q1 is
// equal to itself or not
Console.WriteLine(q1.Equals(q1));
}
}
Example 2: csharp
// C# code to check if two Queue
// class objects are equal or not
using System;
using System.Collections;
class GFG {
// Driver code
public static void Main()
{
// Creating a Queue named q1
Queue q1 = new Queue();
// Adding elements to the Queue
q1.Enqueue("C");
q1.Enqueue("C++");
q1.Enqueue("Java");
q1.Enqueue("C#");
// Creating a Queue named q2
Queue q2 = new Queue();
q2.Enqueue("HTML");
q2.Enqueue("CSS");
q2.Enqueue("PHP");
q2.Enqueue("SQL");
// Checking whether q1 is
// equal to q2 or not
Console.WriteLine(q1.Equals(q2));
// Creating a new Queue
Queue q3 = new Queue();
// Assigning q2 to q3
q3 = q2;
// Checking whether q3 is
// equal to q2 or not
Console.WriteLine(q3.Equals(q2));
}
}
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