SingleOrDefault(TSource) Method (ParallelQuery(TSource), Func(TSource, Boolean))

Task Parallel System.Threading

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.

Namespace:  System.Linq
Assembly:  System.Threading (in System.Threading.dll)

Syntax

Visual Basic (Declaration)
Public Shared Function SingleOrDefault(Of TSource) ( _
	source As ParallelQuery(Of TSource), _
	predicate As Func(Of TSource, Boolean) _
) As TSource
C#
public static TSource SingleOrDefault<TSource>(
	ParallelQuery<TSource> source,
	Func<TSource, bool> predicate
)

Parameters

source
Type: System.Linq..::.ParallelQuery<(Of <(TSource>)>)
The sequence to return the single element of.
predicate
Type: System..::.Func<(Of <(TSource, Boolean>)>)
A function to test an element for a condition.

Type Parameters

TSource
The type of the elements of source.

Return Value

The single element of the input sequence that satisfies the condition, or default(TSource) if no such element is found.

Exceptions

ExceptionCondition
System..::.ArgumentNullException source or predicate is a null reference (Nothing in Visual Basic).
System..::.AggregateException One or more exceptions occurred during the evaluation of the query.
System..::.OperationCanceledException The query was canceled.

See Also