How it works
A Queue models first-in, first-out behavior. Enqueue adds an item at the back, Dequeue removes the oldest item from the front, and Peek observes the oldest item without removing it. This is a more direct expression of a waiting line than repeatedly removing index zero from a list. The collection's operations communicate the intended access pattern to readers.
A queue describes order, not a complete scheduling system. It does not automatically retry failures, enforce fairness between producers, persist jobs, or make several threads safe. In a single-device educational program, it is useful for tracing an ordered workflow step by step. Keep those larger guarantees separate so the presence of a queue does not imply behavior the program has never implemented.
Walk through the example. Three labels enter the queue in the order draft, review, publish. Peek prints draft and leaves the count at three. The loop repeatedly dequeues until no items remain, preserving that arrival order. The final count of zero confirms that the queue was consumed. A second read-only observation would not have changed the processing order.
Watch the boundary. Dequeue and Peek throw when an ordinary queue is empty. Establish the nonempty condition before using them, or use TryDequeue and TryPeek when an empty queue is expected. The check-then-dequeue sequence in this single-threaded example is not a concurrency guarantee. Sharing an ordinary Queue between unsynchronized threads introduces a different problem that this sample does not solve.
Practice independently. Model a print queue with a job label and page count. Enqueue three jobs, inspect the next one, then process them while calculating total pages. Test an empty queue and a job with an invalid page count. Decide whether invalid jobs are rejected when added or when processed, and explain how that decision changes which guarantees the queue can make about its contents.
A working example
using System;
using System.Collections.Generic;
using System.Linq;
using System.Globalization;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
var jobs = new Queue<string>();
jobs.Enqueue("draft");
jobs.Enqueue("review");
jobs.Enqueue("publish");
Console.WriteLine($"next:{jobs.Peek()}; count:{jobs.Count}");
while (jobs.TryDequeue(out string? job)) Console.WriteLine(job);
Console.WriteLine($"remaining:{jobs.Count}");
Expected output
next:draft; count:3 draft review publish remaining:0
Use a queue for arrival order, and define how an empty queue is handled.