Skip to content

Add TryDequeue to Queue #15619

@benaadams

Description

@benaadams

System.Collections.Generic.Queue does not have a TryDequeue method, however its Dequeue is a throwing method so the following pattern always has to be used:

T item ...;
if (queue.Count > 0)
{
    item = queue.Dequeue();
    ...
}

with extra boilerplate for for whatever no item handling; this would be better as:

T item;
if (queue.TryDequeue(out item)
{
    ...
}

As per ConcurrentQueue or TryGet of Dictionary

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions