Mid Collections

How do you peek at the front element of a Queue<T> without dequeuing it?

Again, use the Peek() method:

var front = queue.Peek();

Difference from Dequeue():

  • Peek() returns the front element without removing it.
  • Dequeue() returns and removes the front element.

📘 C# Stack<T> – Interview Questions &

Follow:

More from C# Programming Tutorial

All questions for this course