Queue.Equals() Method in C#

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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));
    }
}

chevron_right


Output:

True

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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));
    }
}

chevron_right


Output:

False
True


My Personal Notes arrow_drop_up