METHOD

Queue<T>.TryPeek

Inspects the front item without removing it. Check the Boolean before using the out value; an empty queue is not an exceptional case.

Formal Syntax & Structure

csharp syntaxcsharp
queue.TryPeek(out var item)

Working Example

Example Snippetcsharp
using System;using System.Collections.Generic;var queue = new Queue<int>(new[] { 0, 5 });Console.WriteLine(queue.TryPeek(out int item) && item == 0 && queue.Count == 2); // True
C# & .NET Reference