Method FindLastIndex
View SourceFindLastIndex<TSource>(IAsyncEnumerable<TSource>, Func<TSource, bool>, CancellationToken)
Searches for an element that matches the conditions defined by the specified predicate and returns the zero-based index of the last occurrence within the entire IAsyncEnumerable<T>.
Declaration
public static ValueTask<int> FindLastIndex<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, bool> predicate, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
IAsyncEnumerable<TSource> | source | The source sequence. |
Func<TSource, bool> | predicate | The predicate that defines the conditions of the element to search for. |
CancellationToken | cancellationToken | The optional cancellation token to be used for cancelling the sequence at any time. |
Returns
Type | Description |
---|---|
ValueTask<int> | The zero-based index of the last occurrence of an element that matches the conditions defined by |
Type Parameters
Name | Description |
---|---|
TSource | The type of elements of |
Remarks
The IAsyncEnumerable<T> is searched forward starting at the first element and ending at the last
element, and the index of the last instance of an element that matches the conditions defined by predicate
is returned.
The predicate
is a delegate to a method that returns true if the object
passed to it matches the conditions defined in the delegate. The elements of the current IAsyncEnumerable<T> are individually passed to the predicate
delegate.
This operator executes immediately.
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
FindLastIndex<TSource>(IAsyncEnumerable<TSource>, Func<TSource, bool>, Index, CancellationToken)
Searches for an element that matches the conditions defined by the specified predicate and returns the zero-based index of the last occurrence within the range of elements in the IAsyncEnumerable<T> that extends backwards from the specified index to the first element.
Declaration
public static ValueTask<int> FindLastIndex<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, bool> predicate, Index index, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
IAsyncEnumerable<TSource> | source | The source sequence. |
Func<TSource, bool> | predicate | The predicate that defines the conditions of the element to search for. |
Index | index | The Index of the ending element within the sequence. |
CancellationToken | cancellationToken | The optional cancellation token to be used for cancelling the sequence at any time. |
Returns
Type | Description |
---|---|
ValueTask<int> | The zero-based index of the last occurrence of an element that matches the conditions defined by |
Type Parameters
Name | Description |
---|---|
TSource | The type of elements of |
Remarks
The IAsyncEnumerable<T> is searched forward starting at the first element and ending at index
, and the index of the last instance of an element that matches the conditions defined by
predicate
is returned.
The predicate
is a delegate to a method that returns true if the object
passed to it matches the conditions defined in the delegate. The elements of the current IAsyncEnumerable<T> are individually passed to the predicate
delegate.
This operator executes immediately.
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
FindLastIndex<TSource>(IAsyncEnumerable<TSource>, Func<TSource, bool>, Index, int, CancellationToken)
Searches for an element that matches the conditions defined by the specified predicate and returns the zero-based index of the last occurrence within the range of elements in the IAsyncEnumerable<T> that ends at the specified index to the last element and contains the specified number of elements.
Declaration
public static ValueTask<int> FindLastIndex<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, bool> predicate, Index index, int count, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
IAsyncEnumerable<TSource> | source | The source sequence. |
Func<TSource, bool> | predicate | The predicate that defines the conditions of the element to search for. |
Index | index | The Index of the ending element within the sequence. |
int | count | The number of elements in the section to search. |
CancellationToken | cancellationToken | The optional cancellation token to be used for cancelling the sequence at any time. |
Returns
Type | Description |
---|---|
ValueTask<int> | The zero-based index of the last occurrence of an element that matches the conditions defined by |
Type Parameters
Name | Description |
---|---|
TSource | The type of elements of |
Remarks
The IAsyncEnumerable<T> is searched forward starting at the first element and ending at index
, and the index of the last instance of an element that matches the conditions defined by
predicate
no earlier in the sequence than count
items before index
is returned.
The predicate
is a delegate to a method that returns true if the object
passed to it matches the conditions defined in the delegate. The elements of the current IAsyncEnumerable<T> are individually passed to the predicate
delegate.
This operator executes immediately.
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentOutOfRangeException |
|