Method LastIndexOf
View SourceLastIndexOf<TSource>(IAsyncEnumerable<TSource>, TSource, CancellationToken)
Searches for the specified object and returns the zero-based index of the last occurrence within the entire IAsyncEnumerable<T>.
Declaration
public static ValueTask<int> LastIndexOf<TSource>(this IAsyncEnumerable<TSource> source, TSource item, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
IAsyncEnumerable<TSource> | source | The source sequence. |
TSource | item | The object to locate in the IAsyncEnumerable<T>. The value can be null for reference types. |
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 |
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 item
is returned.
This method determines equality using the default equality comparer Default
for TSource
, the type of values in the list.
This operator executes immediately.
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
LastIndexOf<TSource>(IAsyncEnumerable<TSource>, TSource, Index, CancellationToken)
Searches for the specified object 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> LastIndexOf<TSource>(this IAsyncEnumerable<TSource> source, TSource item, Index index, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
IAsyncEnumerable<TSource> | source | The source sequence. |
TSource | item | The object to locate in the IAsyncEnumerable<T>. The value can be null for reference types. |
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 |
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 item
is returned.
This method determines equality using the default equality comparer Default
for TSource
, the type of values in the list.
This operator executes immediately.
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentOutOfRangeException |
|
LastIndexOf<TSource>(IAsyncEnumerable<TSource>, TSource, Index, int, CancellationToken)
Searches for the specified object 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> LastIndexOf<TSource>(this IAsyncEnumerable<TSource> source, TSource item, Index index, int count, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
IAsyncEnumerable<TSource> | source | The source sequence. |
TSource | item | The object to locate in the IAsyncEnumerable<T>. The value can be null for reference types. |
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 |
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 item
no earlier in the sequence than
count
items before index
is returned.
This method determines equality using the default equality comparer Default
for TSource
, the type of values in the list.
This operator executes immediately.
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentOutOfRangeException |
|