Editare

Partajați prin


Queue<T>.EnsureCapacity(Int32) Method

Definition

Ensures that the capacity of this queue is at least the specified capacity. If the current capacity is less than capacity, it is increased to at least the specified capacity.

public:
 int EnsureCapacity(int capacity);
public int EnsureCapacity(int capacity);
member this.EnsureCapacity : int -> int
Public Function EnsureCapacity (capacity As Integer) As Integer

Parameters

capacity
Int32

The minimum capacity to ensure.

Returns

The new capacity of this queue.

Remarks

Caution

If capacity comes from user input, prefer letting the collection resize itself as elements are added instead of calling this method. If you must use a user-specified value, either clamp it to a reasonable limit (for example, Math.Clamp(untrustedValue, 0, 20)) or verify that the element count matches the specified value.

Applies to