Op Englesch liesen Editéieren

Deelen iwwer


AsyncEnumerable.Take Method

Definition

Overloads

Take<TSource>(IAsyncEnumerable<TSource>, Int32)

Returns a specified number of contiguous elements from the start of a sequence.

Take<TSource>(IAsyncEnumerable<TSource>, Range)

Returns a specified range of contiguous elements from a sequence.

Take<TSource>(IAsyncEnumerable<TSource>, Int32)

Source:
Take.cs

Returns a specified number of contiguous elements from the start of a sequence.

C#
public static System.Collections.Generic.IAsyncEnumerable<TSource> Take<TSource>(this System.Collections.Generic.IAsyncEnumerable<TSource> source, int count);

Type Parameters

TSource

The type of the elements of source.

Parameters

source
IAsyncEnumerable<TSource>

The sequence to return elements from.

count
Int32

The number of elements to return.

Returns

IAsyncEnumerable<TSource>

An IAsyncEnumerable<T> that contains the specified number of elements from the start of the input sequence.

Exceptions

source is null.

Applies to

.NET 10 an aner Versiounen
Produkt Versiounen
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided), 10
.NET Standard 2.0 (package-provided)

Take<TSource>(IAsyncEnumerable<TSource>, Range)

Source:
Take.cs

Returns a specified range of contiguous elements from a sequence.

C#
public static System.Collections.Generic.IAsyncEnumerable<TSource> Take<TSource>(this System.Collections.Generic.IAsyncEnumerable<TSource> source, Range range);

Type Parameters

TSource

The type of the elements of source.

Parameters

source
IAsyncEnumerable<TSource>

The sequence to return elements from.

range
Range

The range of elements to return, which has start and end indexes either from the start or the end.

Returns

IAsyncEnumerable<TSource>

An IAsyncEnumerable<T> that contains the specified range of elements from the source sequence.

Exceptions

source is null.

Remarks

This method is implemented by using deferred execution. The immediate return value is an object that stores all the information that is required to perform the action. The query represented by this method is not executed until the object is enumerated either by calling its `GetEnumerator` method directly or by using `foreach` in Visual C# or `For Each` in Visual Basic.

Take enumerates source and yields elements whose indices belong to the specified range.

Applies to

.NET 10 an aner Versiounen
Produkt Versiounen
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided), 10
.NET Standard 2.0 (package-provided)