Queue Constructors

Definition

Initializes a new instance of the Queue class.

Overloads

Queue()

Initializes a new instance of the Queue class that is empty, has the default initial capacity, and uses the default growth factor.

Queue(ICollection)

Initializes a new instance of the Queue class that contains elements copied from the specified collection, has the same initial capacity as the number of elements copied, and uses the default growth factor.

Queue(Int32)

Initializes a new instance of the Queue class that is empty, has the specified initial capacity, and uses the default growth factor.

Queue(Int32, Single)

Initializes a new instance of the Queue class that is empty, has the specified initial capacity, and uses the specified growth factor.

Queue()

Source:
Queue.cs
Source:
Queue.cs
Source:
Queue.cs

Initializes a new instance of the Queue class that is empty, has the default initial capacity, and uses the default growth factor.

C#
public Queue();

Remarks

The capacity of a Queue is the number of elements the Queue can hold. As elements are added to a Queue, the capacity is automatically increased as required through reallocation. The capacity can be decreased by calling TrimToSize.

The growth factor is the number by which the current capacity is multiplied when a greater capacity is required. The growth factor is determined when the Queue is constructed.

This constructor is an O(1) operation.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1
UWP 10.0

Queue(ICollection)

Source:
Queue.cs
Source:
Queue.cs
Source:
Queue.cs

Initializes a new instance of the Queue class that contains elements copied from the specified collection, has the same initial capacity as the number of elements copied, and uses the default growth factor.

C#
public Queue(System.Collections.ICollection col);

Parameters

col
ICollection

The ICollection to copy elements from.

Exceptions

col is null.

Remarks

The capacity of a Queue is the number of elements the Queue can hold. As elements are added to a Queue, the capacity is automatically increased as required through reallocation. The capacity can be decreased by calling TrimToSize.

The growth factor is the number by which the current capacity is multiplied when a greater capacity is required. The growth factor is determined when the Queue is constructed.

The elements are copied onto the Queue in the same order they are read by the IEnumerator of the ICollection.

This constructor is an O(n) operation, where n is the number of elements in col.

See also

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1
UWP 10.0

Queue(Int32)

Source:
Queue.cs
Source:
Queue.cs
Source:
Queue.cs

Initializes a new instance of the Queue class that is empty, has the specified initial capacity, and uses the default growth factor.

C#
public Queue(int capacity);

Parameters

capacity
Int32

The initial number of elements that the Queue can contain.

Exceptions

capacity is less than zero.

Remarks

The capacity of a Queue is the number of elements the Queue can hold. As elements are added to a Queue, the capacity is automatically increased as required through reallocation. The capacity can be decreased by calling TrimToSize.

The growth factor is the number by which the current capacity is multiplied when a greater capacity is required. The growth factor is determined when the Queue is constructed.

If the size of the collection can be estimated, specifying the initial capacity eliminates the need to perform a number of resizing operations while adding elements to the Queue.

This constructor is an O(n) operation, where n is capacity.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1
UWP 10.0

Queue(Int32, Single)

Source:
Queue.cs
Source:
Queue.cs
Source:
Queue.cs

Initializes a new instance of the Queue class that is empty, has the specified initial capacity, and uses the specified growth factor.

C#
public Queue(int capacity, float growFactor);

Parameters

capacity
Int32

The initial number of elements that the Queue can contain.

growFactor
Single

The factor by which the capacity of the Queue is expanded.

Exceptions

capacity is less than zero.

-or-

growFactor is less than 1.0 or greater than 10.0.

Remarks

The capacity of a Queue is the number of elements the Queue can hold. As elements are added to a Queue, the capacity is automatically increased as required through reallocation. The capacity can be decreased by calling TrimToSize.

The growth factor is the number by which the current capacity is multiplied when a greater capacity is required. The growth factor is determined when the Queue is constructed. The capacity of the Queue will always increase by a minimum value, regardless of the growth factor; a growth factor of 1.0 will not prevent the Queue from increasing in size.

If the size of the collection can be estimated, specifying the initial capacity eliminates the need to perform a number of resizing operations while adding elements to the Queue.

This constructor is an O(n) operation, where n is capacity.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1
UWP 10.0