ParallelEnumerable.FirstOrDefault 方法

定义

返回并行序列中的第一个元素;如果该序列中不包含任何元素,则返回默认值。Returns the first element of a parallel sequence, or a default value if the sequence contains no elements.

重载

FirstOrDefault<TSource>(ParallelQuery<TSource>)

返回并行序列中的第一个元素;如果该序列中不包含任何元素,则返回默认值。Returns the first element of a parallel sequence, or a default value if the sequence contains no elements.

FirstOrDefault<TSource>(ParallelQuery<TSource>, Func<TSource,Boolean>)

返回并行序列中满足条件的第一个元素;如果未找到这样的元素,则返回默认值。Returns the first element of the parallel sequence that satisfies a condition or a default value if no such element is found.

FirstOrDefault<TSource>(ParallelQuery<TSource>)

返回并行序列中的第一个元素;如果该序列中不包含任何元素,则返回默认值。Returns the first element of a parallel sequence, or a default value if the sequence contains no elements.

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

类型参数

TSource

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

参数

source
ParallelQuery<TSource>

要返回其第一个元素的序列。The sequence to return the first element of.

返回

TSource

如果 source 为空,则返回 default(TSource);否则返回 source 中的第一个元素。default(TSource) if source is empty; otherwise, the first element in source.

异常

已使用通过 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.

注解

如果查询未排序,则第一个元素是不确定的。If the query is not ordered, then the first element is non-deterministic. 有关详细信息,请参阅 PLINQ 中的顺序保留For more information, see Order Preservation in PLINQ.

另请参阅

FirstOrDefault<TSource>(ParallelQuery<TSource>, Func<TSource,Boolean>)

返回并行序列中满足条件的第一个元素;如果未找到这样的元素,则返回默认值。Returns the first element of the parallel sequence that satisfies a condition or a default value if no such element is found.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static TSource FirstOrDefault(System::Linq::ParallelQuery<TSource> ^ source, Func<TSource, bool> ^ predicate);
public static TSource FirstOrDefault<TSource> (this System.Linq.ParallelQuery<TSource> source, Func<TSource,bool> predicate);
static member FirstOrDefault : System.Linq.ParallelQuery<'Source> * Func<'Source, bool> -> 'Source
<Extension()>
Public Function FirstOrDefault(Of TSource) (source As ParallelQuery(Of TSource), predicate As Func(Of TSource, Boolean)) As TSource

类型参数

TSource

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

参数

source
ParallelQuery<TSource>

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

predicate
Func<TSource,Boolean>

用于测试每个元素是否满足条件的函数。A function to test each element for a condition.

返回

TSource

如果 source 为空或没有元素通过 predicate 指定的测试,则返回 default(TSource),否则返回 source 中通过 predicate 指定的测试的第一个元素。default(TSource) if source is empty or if no element passes the test specified by predicate; otherwise, the first element in source that passes the test specified by predicate.

异常

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

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

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

注解

如果查询未排序,则第一个元素是不确定的。If the query is not ordered, then the first element is non-deterministic. 有关详细信息,请参阅 PLINQ 中的顺序保留For more information, see Order Preservation in PLINQ.

另请参阅

适用于