Blog Logo
TAGS

PriorityQueues on .NET 7 and C# 11

Starting from .NET 6 and C# 10, we finally have built-in support for PriorityQueues 🥳 A PriorityQueue is a collection of items that have a value and a priority; as you can imagine, they act as a queue: the main operations are “add an item to the queue”, called Enqueue, and “remove an item from the queue”, named Dequeue. The main difference from a simple Queue is that on dequeue, the item with lowest priority is removed. In this article, we’re gonna use a PriorityQueue and wrap it into a custom class to solve one of its design issues (that I hope they’ll be addressed in a future release of dotNET). This is the essence of a Priority Queue: insert items, give them a priority, then remove them starting from the one with lower priority.