Queue.Contains() Method in C#The Queue. contains() function in C# determines the existence of a certain element inside a Queue collection. It produces a Boolean result (true/false) indicating if the element is present in the Queue. This method compares elements using the element type's predefined equivalence comparer. It returns true if the Queue includes the specified element; otherwise, it returns false value. It helps in the efficient verification of an item's existence within the Queue without affecting its arrangement or content. Queues in C# are a first-in, first-out (FIFO) data structure in which components are added at the end and discarded at the beginning. The Contains() function is a useful tool for determining whether an element is already present in the Queue before executing other actions. Syntax:It has the following syntax: public virtual bool Contains(object ob); Here, ob refers to the object to be located in the queue, which value might be null. Return Value:If the element exists within the Queue, the method returns True; otherwise, it returns False. Example 1:Let us take a C# program to implement the Queue.contains() method. Output: False Example 2:Let us take a C# program to implement the Queue.contains() method. Output: True Advantages of Queue.Contains() Method in C#There are several advantages of the Queue.Contains() method in C#. Some main advantages of this method are as follows:
Next TopicQueue.Enqueue() Method in C# |