Skip to content

)} ,System.Func{--0,System.Boolean})}

Observable.SingleOrDefault(IObservable) method

Defined in

Type: Observable Namespace: System.Reactive.Linq Assembly: System.Reactive.dll

Applies to

netstandard2.0

Overloads

  • 1. public static TSource SingleOrDefault<TSource>(this IObservable<TSource> source)
  • 2. public static TSource SingleOrDefault<TSource>(this IObservable<TSource> source, Func<TSource, bool> predicate)

1. Overload

Deprecated

This blocking operation is no longer supported. Instead, use the async version in combination with C# and Visual Basic async/await support. In case you need a blocking operation, use Wait or convert the resulting observable sequence to a Task object and block.

Attributes: [Obsolete("This blocking operation is no longer supported. Instead, use the async version in combination with C# and Visual Basic async/await support. In case you need a blocking operation, use Wait or convert the resulting observable sequence to a Task object and block.")]

public static TSource SingleOrDefault<TSource>(this IObservable<TSource> source)

Summary: Returns the only element of an observable sequence, or a default value if the observable sequence is empty; this method throws an exception if there is more than one element in the observable sequence.

Type parameters

NameDescription
TSourceThe type of the elements in the source sequence.

Parameters

NameTypeDescription
sourceIObservableSource observable sequence.

Returns: TSource -- The single element in the observable sequence, or a default value if no such element exists.

Exceptions

TypeCondition
System.ArgumentNullExceptionsource is null.
System.InvalidOperationExceptionThe source sequence contains more than one element.

See also

2. Overload

Deprecated

This blocking operation is no longer supported. Instead, use the async version in combination with C# and Visual Basic async/await support. In case you need a blocking operation, use Wait or convert the resulting observable sequence to a Task object and block.

Attributes: [Obsolete("This blocking operation is no longer supported. Instead, use the async version in combination with C# and Visual Basic async/await support. In case you need a blocking operation, use Wait or convert the resulting observable sequence to a Task object and block.")]

public static TSource SingleOrDefault<TSource>(this IObservable<TSource> source, Func<TSource, bool> predicate)

Summary: Returns the only element of an observable sequence that satisfies the condition in the predicate, or a default value if no such element exists; this method throws an exception if there is more than one element matching the predicate in the observable sequence.

Type parameters

NameDescription
TSourceThe type of the elements in the source sequence.

Parameters

NameTypeDescription
sourceIObservableSource observable sequence.
predicateFuncA predicate function to evaluate for elements in the source sequence.

Returns: TSource -- The single element in the observable sequence that satisfies the condition in the predicate, or a default value if no such element exists.

Exceptions

TypeCondition
System.ArgumentNullExceptionsource or predicate is null.
System.InvalidOperationExceptionThe sequence contains more than one element that satisfies the condition in the predicate.

See also