Skip to content

,System.Int32)} ,System.Int32,System.Reactive.Concurrency.IScheduler)} ,System.TimeSpan)} ,System.TimeSpan,System.Reactive.Concurrency.IScheduler)}

Qbservable.Take(IQbservable, int) method

Defined in

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

Applies to

netstandard2.0

Overloads

  • 1. public static IQbservable<TSource> Take<TSource>(this IQbservable<TSource> source, int count)
  • 2. public static IQbservable<TSource> Take<TSource>(this IQbservable<TSource> source, int count, IScheduler scheduler)
  • 3. public static IQbservable<TSource> Take<TSource>(this IQbservable<TSource> source, TimeSpan duration)
  • 4. public static IQbservable<TSource> Take<TSource>(this IQbservable<TSource> source, TimeSpan duration, IScheduler scheduler)

1. Overload

public static IQbservable<TSource> Take<TSource>(this IQbservable<TSource> source, int count)

Summary: Returns a specified number of contiguous elements from the start of an observable sequence.

Type parameters

NameDescription
TSourceThe type of the elements in the source sequence.

Parameters

NameTypeDescription
source[IQbservable](#The sequence to take elements from.
countintThe number of elements to return.

Returns: IQbservable -- An observable sequence that contains the specified number of elements from the start of the input sequence.

Exceptions

TypeCondition
System.ArgumentNullExceptionsource is null.
System.ArgumentOutOfRangeExceptioncount is less than zero.

2. Overload

public static IQbservable<TSource> Take<TSource>(this IQbservable<TSource> source, int count, IScheduler scheduler)

Summary: Returns a specified number of contiguous elements from the start of an observable sequence, using the specified scheduler for the edge case of Take(0).

Type parameters

NameDescription
TSourceThe type of the elements in the source sequence.

Parameters

NameTypeDescription
source[IQbservable](#The sequence to take elements from.
countintThe number of elements to return.
scheduler[IScheduler](#Scheduler used to produce an OnCompleted message in case count is set to 0.

Returns: IQbservable -- An observable sequence that contains the specified number of elements from the start of the input sequence.

Exceptions

TypeCondition
System.ArgumentNullExceptionsource or scheduler is null.
System.ArgumentOutOfRangeExceptioncount is less than zero.

3. Overload

public static IQbservable<TSource> Take<TSource>(this IQbservable<TSource> source, TimeSpan duration)

Summary: Takes elements for the specified duration from the start of the observable source sequence.

Type parameters

NameDescription
TSourceThe type of the elements in the source sequence.

Parameters

NameTypeDescription
source[IQbservable](#Source sequence to take elements from.
durationTimeSpanDuration for taking elements from the start of the sequence.

Returns: IQbservable -- An observable sequence with the elements taken during the specified duration from the start of the source sequence.

Remarks

Specifying a TimeSpan.Zero value for duration doesn't guarantee an empty sequence will be returned. This is a side-effect of the asynchrony introduced by the scheduler, where the action that stops forwarding callbacks from the source sequence may not execute immediately, despite the TimeSpan.Zero due time.

Exceptions

TypeCondition
System.ArgumentNullExceptionsource is null.
System.ArgumentOutOfRangeExceptionduration is less than TimeSpan.Zero.

4. Overload

public static IQbservable<TSource> Take<TSource>(this IQbservable<TSource> source, TimeSpan duration, IScheduler scheduler)

Summary: Takes elements for the specified duration from the start of the observable source sequence, using the specified scheduler to run timers.

Type parameters

NameDescription
TSourceThe type of the elements in the source sequence.

Parameters

NameTypeDescription
source[IQbservable](#Source sequence to take elements from.
durationTimeSpanDuration for taking elements from the start of the sequence.
scheduler[IScheduler](#Scheduler to run the timer on.

Returns: IQbservable -- An observable sequence with the elements taken during the specified duration from the start of the source sequence.

Remarks

Specifying a TimeSpan.Zero value for duration doesn't guarantee an empty sequence will be returned. This is a side-effect of the asynchrony introduced by the scheduler, where the action that stops forwarding callbacks from the source sequence may not execute immediately, despite the TimeSpan.Zero due time.

Exceptions

TypeCondition
System.ArgumentNullExceptionsource or scheduler is null.
System.ArgumentOutOfRangeExceptionduration is less than TimeSpan.Zero.