The Dequeue() method is used to returns the object at the beginning of the Queue. This method is similar to the Peek() Method. The only difference between Dequeue and Peek method is that Peek() method will not modify the Queue but Dequeue will modify. This method is an O(1) operation and comes under
public T Dequeue ();
Return value: It returns the object which is removed from the beginning of the Queue.
Exception: The method throws InvalidOperationException on calling empty queue, therefore always check that the total count of a queue is greater than zero before calling the Dequeue() method.
Below programs illustrate the use of the above-discussed method:
Number of elements in the Queue: 4 Top element of queue is: 3 Number of elements in the Queue: 3
Number of elements in the Queue: 2 Top element of queue is: 2 Number of elements in the Queue: 1
- C# | Get the object at the beginning of the Queue - Peek Operation
- C# | Add an object to the end of the Queue - Enqueue Operation
- C# | Check if an array object is equal to another array object
- C# Queue with Examples
- Queue.Contains() Method in C#
- How to create a Queue in C#
- C# | Queue Class
- C# | Convert Queue To array
- Queue.Clone() Method in C#
- Queue.Peek Method in C#
- Queue.Clear Method in C#
- Getting enumerator that iterates through the Queue in C#
- Queue.Count Property in C#
- Queue.IsSynchronized Property in C#
- Queue.CopyTo() Method in C#
- Queue.Enqueue() Method in C#
- Queue.Dequeue Method in C#
- Queue.Synchronized() Method in C#
- Queue.ToArray Method in C#
- Queue.GetEnumerator Method in C#
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.