A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/c-sharp/queue-equals-method-in-c-sharp/ below:

Queue.Equals() Method in C# - GeeksforGeeks

Queue.Equals() Method in C#

Last Updated : 11 Jul, 2025

Equals(Object) Method

which is inherited from the

Object class

is used to check if a specified

Queue class

object 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,

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 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