Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Queue.Equals() Method in C#
The Queue.Equals() method in C# is used to check if a queue object is equal to another queue object.
Syntax
The syntax is as follows −
public virtual bool Equals (object obj);
Above, the parameter obj is for comparison.
Example
Let us now see an example −
using System;
using System.Collections.Generic;
public class Demo {
public static void Main(){
Queue<string> queue = new Queue<string>();
queue.Enqueue("Gary");
queue.Enqueue("Jack");
queue.Enqueue("Ryan");
queue.Enqueue("Kevin");
queue.Enqueue("Mark");
queue.Enqueue("Jack");
queue.Enqueue("Ryan");
queue.Enqueue("Kevin");
Console.WriteLine(queue.Equals(queue));
Console.Write("Count of elements = ");
Console.WriteLine(queue.Count);
queue.Clear();
Console.Write("Count of elements (updated) = ");
Console.WriteLine(queue.Count);
}
}
Output
This will produce the following output −
True Count of elements = 8 Count of elements (updated) = 0
Example
Let us now see another example −
using System;
using System.Collections;
public class Demo {
public static void Main(){
Queue queue = new Queue();
queue.Enqueue(100);
queue.Enqueue(200);
queue.Enqueue(300);
queue.Enqueue(400);
Queue queue2 = new Queue();
queue2.Enqueue(100);
queue2.Enqueue(150);
queue2.Enqueue(300);
queue2.Enqueue(400);
Console.WriteLine(queue.Equals(queue2));
}
}
Output
This will produce the following output −
False
Advertisements