Method FindIndex
View SourceFindIndex<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 first occurrence within the entire IAsyncEnumerable<T>.
Declaration
public static ValueTask<int> FindIndex<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 first 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.
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 |
|
FindIndex<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 first occurrence within the range of elements in the IAsyncEnumerable<T> that extends from the specified index to the last element.
Declaration
public static ValueTask<int> FindIndex<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 starting 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 first 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 index
and ending at the
last element.
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 |
|
FindIndex<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 first occurrence within the range of elements in the IAsyncEnumerable<T> that starts at the specified index to the last element and contains the specified number of elements.
Declaration
public static ValueTask<int> FindIndex<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 starting 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 first 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 index
and ending at
index
plus count
minus 1
, if count is greater than 0
.
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 |
|