ConcurrentStack<T>.TryPopRange 方法

定义

重载

TryPopRange(T[], Int32, Int32)

尝试自动弹出并返回 ConcurrentStack<T> 顶部的多个对象。Attempts to pop and return multiple objects from the top of the ConcurrentStack<T> atomically.

TryPopRange(T[])

尝试自动弹出并返回 ConcurrentStack<T> 顶部的多个对象。Attempts to pop and return multiple objects from the top of the ConcurrentStack<T> atomically.

TryPopRange(T[], Int32, Int32)

尝试自动弹出并返回 ConcurrentStack<T> 顶部的多个对象。Attempts to pop and return multiple objects from the top of the ConcurrentStack<T> atomically.

public:
 int TryPopRange(cli::array <T> ^ items, int startIndex, int count);
public int TryPopRange (T[] items, int startIndex, int count);
member this.TryPopRange : 'T[] * int * int -> int
Public Function TryPopRange (items As T(), startIndex As Integer, count As Integer) As Integer

参数

items
T[]

要将从 Array 顶部弹出的对象添加到的 ConcurrentStack<T>The Array to which objects popped from the top of the ConcurrentStack<T> will be added.

startIndex
Int32

items 中从零开始的偏移量,在此开始从 ConcurrentStack<T> 顶部插入元素。The zero-based offset in items at which to begin inserting elements from the top of the ConcurrentStack<T>.

count
Int32

ConcurrentStack<T> 顶部弹出并插入 items 中的元素数。The number of elements to be popped from top of the ConcurrentStack<T> and inserted into items.

返回

成功从堆栈顶部弹出并插入 items 中的对象数。The number of objects successfully popped from the top of the stack and inserted in items.

异常

items 为 null 引用(在 Visual Basic 中为 Nothing)。items is a null reference (Nothing in Visual Basic).

startIndexcount 为负数。startIndex or count is negative. startIndex 大于或等于 items 的长度。Or startIndex is greater than or equal to the length of items.

startIndex + count 大于 items 的长度。startIndex + count is greater than the length of items.

注解

当弹出多个项时,如果堆栈上几乎没有争用,使用 TryPopRange 可能比使用每个要删除的项 TryPop 一次更为有效。When popping multiple items, if there is little contention on the stack, using TryPopRange can be more efficient than using TryPop once per item to be removed. 节点填写 items 数组,其中包含要在 startIndex 下弹出的第一项,第二个项将以 startIndex + 1 的方式弹出,依此类推。Nodes fill the items array with the first item to be popped at the startIndex, the second item to be popped at startIndex + 1, and so on.

另请参阅

TryPopRange(T[])

尝试自动弹出并返回 ConcurrentStack<T> 顶部的多个对象。Attempts to pop and return multiple objects from the top of the ConcurrentStack<T> atomically.

public:
 int TryPopRange(cli::array <T> ^ items);
public int TryPopRange (T[] items);
member this.TryPopRange : 'T[] -> int
Public Function TryPopRange (items As T()) As Integer

参数

items
T[]

要将从 Array 顶部弹出的对象添加到的 ConcurrentStack<T>The Array to which objects popped from the top of the ConcurrentStack<T> will be added.

返回

成功从 ConcurrentStack<T> 顶部弹出并插入 items 中的对象数。The number of objects successfully popped from the top of the ConcurrentStack<T> and inserted in items.

异常

items 是 null 参数(在 Visual Basic 中为 Nothing)。items is a null argument (Nothing in Visual Basic).

注解

当弹出多个项时,如果堆栈上几乎没有争用,使用 TryPopRange 可能比使用每个要删除的项 TryPop 一次更为有效。When popping multiple items, if there is little contention on the stack, using TryPopRange can be more efficient than using TryPop once per item to be removed. 节点填写 items 数组,其中包含要在 startIndex 下弹出的第一项,第二个项将以 startIndex + 1 的方式弹出,依此类推。Nodes fill the items array with the first item to be popped at the startIndex, the second item to be popped at startIndex + 1, and so on.

有关代码示例,请参阅ConcurrentStack<T>For a code example, see ConcurrentStack<T>.

另请参阅

适用于