ParallelEnumerable.ElementAtOrDefault<TSource>(ParallelQuery<TSource>, Int32) 方法

定义

返回并行序列中指定索引处的元素;如果索引超出范围,则返回默认值。Returns the element at a specified index in a parallel sequence or a default value if the index is out of range.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static TSource ElementAtOrDefault(System::Linq::ParallelQuery<TSource> ^ source, int index);
public static TSource ElementAtOrDefault<TSource> (this System.Linq.ParallelQuery<TSource> source, int index);
static member ElementAtOrDefault : System.Linq.ParallelQuery<'Source> * int -> 'Source
<Extension()>
Public Function ElementAtOrDefault(Of TSource) (source As ParallelQuery(Of TSource), index As Integer) As TSource

类型参数

TSource

source 的元素类型。The type of the elements of source.

参数

source
ParallelQuery<TSource>

要从中返回元素的序列。A sequence to return an element from.

index
Int32

要检索的从零开始的元素索引。The zero-based index of the element to retrieve.

返回

TSource

如果索引超出源序列的范围,则为 default(TSource);否则为源序列中指定位置处的元素。default(TSource) if the index is outside the bounds of the source sequence; otherwise, the element at the specified position in the source sequence.

异常

已使用通过 WithCancellation 传递的令牌取消了查询。The query was canceled with the token passed in through WithCancellation.

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

评估查询期间发生一个或多个异常。One or more exceptions occurred during the evaluation of the query.

适用于

另请参阅