Skip to content

)} ,--0)}

Observable.DefaultIfEmpty(IObservable) method

Defined in

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

Applies to

netstandard2.0

Overloads

  • 1. public static IObservable<TSource?> DefaultIfEmpty<TSource>(this IObservable<TSource> source)
  • 2. public static IObservable<TSource> DefaultIfEmpty<TSource>(this IObservable<TSource> source, TSource defaultValue)

1. Overload

public static IObservable<TSource?> DefaultIfEmpty<TSource>(this IObservable<TSource> source)

Summary: Returns the elements of the specified sequence or the type parameter's default value in a singleton sequence if the sequence is empty.

Type parameters

NameDescription
TSourceThe type of the elements in the source sequence (if any), whose default value will be taken if the sequence is empty.

Parameters

NameTypeDescription
sourceIObservableThe sequence to return a default value for if it is empty.

Returns: IObservable -- An observable sequence that contains the default value for the TSource type if the source is empty; otherwise, the elements of the source itself.

Exceptions

TypeCondition
System.ArgumentNullExceptionsource is null.

2. Overload

public static IObservable<TSource> DefaultIfEmpty<TSource>(this IObservable<TSource> source, TSource defaultValue)

Summary: Returns the elements of the specified sequence or the specified value in a singleton sequence if the sequence is empty.

Type parameters

NameDescription
TSourceThe type of the elements in the source sequence (if any), and the specified default value which will be taken if the sequence is empty.

Parameters

NameTypeDescription
sourceIObservableThe sequence to return the specified value for if it is empty.
defaultValueTSourceThe value to return if the sequence is empty.

Returns: IObservable -- An observable sequence that contains the specified default value if the source is empty; otherwise, the elements of the source itself.

Exceptions

TypeCondition
System.ArgumentNullExceptionsource is null.