ParallelEnumerable.SingleOrDefault 方法

定义

返回并行序列中的唯一元素;如果该序列为空,则返回默认值;如果该序列包含多个元素,此方法将引发异常。Returns the only element of a parallel sequence, or a default value if the sequence is empty; this method throws an exception if there is more than one element in the sequence.

重载

SingleOrDefault<TSource>(ParallelQuery<TSource>)

返回并行序列中的唯一元素;如果该序列为空,则返回默认值;如果该序列包含多个元素,此方法将引发异常。Returns the only element of a parallel sequence, or a default value if the sequence is empty; this method throws an exception if there is more than one element in the sequence.

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

返回并行序列中满足指定条件的唯一元素;如果这类元素不存在,则返回默认值;如果有多个元素满足该条件,此方法将引发异常。Returns the only element of a parallel sequence that satisfies a specified condition or a default value if no such element exists; this method throws an exception if more than one element satisfies the condition.

SingleOrDefault<TSource>(ParallelQuery<TSource>)

返回并行序列中的唯一元素;如果该序列为空,则返回默认值;如果该序列包含多个元素,此方法将引发异常。Returns the only element of a parallel sequence, or a default value if the sequence is empty; this method throws an exception if there is more than one element in the sequence.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static TSource SingleOrDefault(System::Linq::ParallelQuery<TSource> ^ source);
public static TSource SingleOrDefault<TSource> (this System.Linq.ParallelQuery<TSource> source);
static member SingleOrDefault : System.Linq.ParallelQuery<'Source> -> 'Source
<Extension()>
Public Function SingleOrDefault(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 single element of.

返回

TSource

返回输入序列的单个元素;如果序列不包含任何元素,则返回 default()。The single element of the input sequence, or default() if the sequence contains no elements.

异常

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

source 具有多个元素。source has more than one element.

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

另请参阅

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

返回并行序列中满足指定条件的唯一元素;如果这类元素不存在,则返回默认值;如果有多个元素满足该条件,此方法将引发异常。Returns the only element of a parallel sequence that satisfies a specified condition or a default value if no such element exists; this method throws an exception if more than one element satisfies the condition.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static TSource SingleOrDefault(System::Linq::ParallelQuery<TSource> ^ source, Func<TSource, bool> ^ predicate);
public static TSource SingleOrDefault<TSource> (this System.Linq.ParallelQuery<TSource> source, Func<TSource,bool> predicate);
static member SingleOrDefault : System.Linq.ParallelQuery<'Source> * Func<'Source, bool> -> 'Source
<Extension()>
Public Function SingleOrDefault(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 the single element of.

predicate
Func<TSource,Boolean>

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

返回

TSource

输入序列中满足条件的单个元素,如果未找到这样的元素,则为 default()。The single element of the input sequence that satisfies the condition, or default() if no such element is found.

异常

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

source 是空的,或者返回了多个元素。source is empty or multiple elements are returned.

另请参阅

适用于