Enumerable
Provides a set of static (Shared in Visual Basic) methods for
querying objects that implement IEnumerable<T>.
public static TSource Aggregate<TSource>(this IEnumerable<TSource> source, Func<TSource, TSource, TSource> func)
Applies an accumulator function over a sequence.
public static TAccumulate Aggregate<TSource, TAccumulate>(this IEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> func)
Applies an accumulator function over a sequence. The specified
seed value is used as the initial accumulator value.
public static TResult Aggregate<TSource, TAccumulate, TResult>(this IEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> func, Func<TAccumulate, TResult> resultSelector)
Applies an accumulator function over a sequence. The specified
seed value is used as the initial accumulator value, and the
specified function is used to select the result value.
Determines whether all elements of a sequence satisfy a condition.
Determines whether a sequence contains any elements.
Determines whether any element of a sequence satisfies a
condition.
Returns the input typed as IEnumerable<T>.
Computes the average of a sequence of nullable Int32 values.
public static double Average<TSource>(this IEnumerable<TSource> source, Func<TSource, int> selector)
Computes the average of a sequence of nullable Int32 values
that are obtained by invoking a transform function on each
element of the input sequence.
Computes the average of a sequence of Int32 values.
public static double? Average<TSource>(this IEnumerable<TSource> source, Func<TSource, int?> selector)
Computes the average of a sequence of Int32 values
that are obtained by invoking a transform function on each
element of the input sequence.
Computes the average of a sequence of nullable Int64 values.
public static double Average<TSource>(this IEnumerable<TSource> source, Func<TSource, long> selector)
Computes the average of a sequence of nullable Int64 values
that are obtained by invoking a transform function on each
element of the input sequence.
Computes the average of a sequence of Int64 values.
public static double? Average<TSource>(this IEnumerable<TSource> source, Func<TSource, long?> selector)
Computes the average of a sequence of Int64 values
that are obtained by invoking a transform function on each
element of the input sequence.
Computes the average of a sequence of nullable Single values.
public static float Average<TSource>(this IEnumerable<TSource> source, Func<TSource, float> selector)
Computes the average of a sequence of nullable Single values
that are obtained by invoking a transform function on each
element of the input sequence.
Computes the average of a sequence of Single values.
public static float? Average<TSource>(this IEnumerable<TSource> source, Func<TSource, float?> selector)
Computes the average of a sequence of Single values
that are obtained by invoking a transform function on each
element of the input sequence.
Computes the average of a sequence of nullable Double values.
public static double Average<TSource>(this IEnumerable<TSource> source, Func<TSource, double> selector)
Computes the average of a sequence of nullable Double values
that are obtained by invoking a transform function on each
element of the input sequence.
Computes the average of a sequence of Double values.
public static double? Average<TSource>(this IEnumerable<TSource> source, Func<TSource, double?> selector)
Computes the average of a sequence of Double values
that are obtained by invoking a transform function on each
element of the input sequence.
Computes the average of a sequence of nullable Decimal values.
public static decimal Average<TSource>(this IEnumerable<TSource> source, Func<TSource, decimal> selector)
Computes the average of a sequence of nullable Decimal values
that are obtained by invoking a transform function on each
element of the input sequence.
Computes the average of a sequence of Decimal values.
public static decimal? Average<TSource>(this IEnumerable<TSource> source, Func<TSource, decimal?> selector)
Computes the average of a sequence of Decimal values
that are obtained by invoking a transform function on each
element of the input sequence.
Converts the elements of an IEnumerable to the
specified type.
public static IEnumerable<TSource> Concat<TSource>(this IEnumerable<TSource> first, IEnumerable<TSource> second)
Concatenates two sequences.
Determines whether a sequence contains a specified element by
using the default equality comparer.
public static bool Contains<TSource>(this IEnumerable<TSource> source, TSource value, IEqualityComparer<TSource> comparer)
Determines whether a sequence contains a specified element by
using a specified IEqualityComparer<T>.
Returns the number of elements in a sequence.
Returns a number that represents how many elements in the
specified sequence satisfy a condition.
Returns the elements of the specified sequence or the type
parameter's default value in a singleton collection if the
sequence is empty.
public static IEnumerable<TSource> DefaultIfEmpty<TSource>(this IEnumerable<TSource> source, TSource defaultValue)
Returns the elements of the specified sequence or the specified
value in a singleton collection if the sequence is empty.
Returns distinct elements from a sequence by using the default
equality comparer to compare values.
public static IEnumerable<TSource> Distinct<TSource>(this IEnumerable<TSource> source, IEqualityComparer<TSource> comparer)
Returns distinct elements from a sequence by using a specified
IEqualityComparer<T> to compare values.
Returns the element at a specified index in a sequence.
Returns the element at a specified index in a sequence or a
default value if the index is out of range.
Returns an empty IEnumerable<T> that has the
specified type argument.
public static IEnumerable<TSource> Except<TSource>(this IEnumerable<TSource> first, IEnumerable<TSource> second)
Produces the set difference of two sequences by using the
default equality comparer to compare values.
public static IEnumerable<TSource> Except<TSource>(this IEnumerable<TSource> first, IEnumerable<TSource> second, IEqualityComparer<TSource> comparer)
Produces the set difference of two sequences by using the
specified IEqualityComparer<T> to compare values.
Returns the first element of a sequence.
public static TSource First<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
Returns the first element in a sequence that satisfies a specified condition.
Returns the first element of a sequence, or a default value if
the sequence contains no elements.
public static TSource FirstOrDefault<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
Returns the first element of the sequence that satisfies a
condition or a default value if no such element is found.
public static IEnumerable<IGrouping<TKey, TSource>> GroupBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
Groups the elements of a sequence according to a specified key
selector function.
public static IEnumerable<IGrouping<TKey, TSource>> GroupBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer)
Groups the elements of a sequence according to a specified key
selector function and compares the keys by using a specified
comparer.
public static IEnumerable<IGrouping<TKey, TElement>> GroupBy<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector)
Groups the elements of a sequence according to a specified key
selector function and projects the elements for each group by
using a specified function.
public static IEnumerable<IGrouping<TKey, TElement>> GroupBy<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer)
Groups the elements of a sequence according to a specified key
selector function and creates a result value from each group and
its key.
public static IEnumerable<TResult> GroupBy<TSource, TKey, TResult>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TKey, IEnumerable<TSource>, TResult> resultSelector)
Groups the elements of a sequence according to a key selector
function. The keys are compared by using a comparer and each
group's elements are projected by using a specified function.
public static IEnumerable<TResult> GroupBy<TSource, TKey, TResult>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TKey, IEnumerable<TSource>, TResult> resultSelector, IEqualityComparer<TKey> comparer)
Groups the elements of a sequence according to a specified key
selector function and creates a result value from each group and
its key. The elements of each group are projected by using a
specified function.
public static IEnumerable<TResult> GroupBy<TSource, TKey, TElement, TResult>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, Func<TKey, IEnumerable<TElement>, TResult> resultSelector)
Groups the elements of a sequence according to a specified key
selector function and creates a result value from each group and
its key. The keys are compared by using a specified comparer.
public static IEnumerable<TResult> GroupBy<TSource, TKey, TElement, TResult>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, Func<TKey, IEnumerable<TElement>, TResult> resultSelector, IEqualityComparer<TKey> comparer)
Groups the elements of a sequence according to a specified key
selector function and creates a result value from each group and
its key. Key values are compared by using a specified comparer,
and the elements of each group are projected by using a
specified function.
public static IEnumerable<TResult> GroupJoin<TOuter, TInner, TKey, TResult>(this IEnumerable<TOuter> outer, IEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, IEnumerable<TInner>, TResult> resultSelector)
Correlates the elements of two sequences based on equality of
keys and groups the results. The default equality comparer is
used to compare keys.
public static IEnumerable<TResult> GroupJoin<TOuter, TInner, TKey, TResult>(this IEnumerable<TOuter> outer, IEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, IEnumerable<TInner>, TResult> resultSelector, IEqualityComparer<TKey> comparer)
Correlates the elements of two sequences based on equality of
keys and groups the results. The default equality comparer is
used to compare keys. A specified IEqualityComparer<T>
is used to compare keys.
public static IEnumerable<TSource> Intersect<TSource>(this IEnumerable<TSource> first, IEnumerable<TSource> second)
Produces the set intersection of two sequences by using the
default equality comparer to compare values.
public static IEnumerable<TSource> Intersect<TSource>(this IEnumerable<TSource> first, IEnumerable<TSource> second, IEqualityComparer<TSource> comparer)
Produces the set intersection of two sequences by using the
specified IEqualityComparer<T> to compare values.
public static IEnumerable<TResult> Join<TOuter, TInner, TKey, TResult>(this IEnumerable<TOuter> outer, IEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, TInner, TResult> resultSelector)
Correlates the elements of two sequences based on matching keys.
The default equality comparer is used to compare keys.
public static IEnumerable<TResult> Join<TOuter, TInner, TKey, TResult>(this IEnumerable<TOuter> outer, IEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, TInner, TResult> resultSelector, IEqualityComparer<TKey> comparer)
Correlates the elements of two sequences based on matching keys.
The default equality comparer is used to compare keys. A
specified IEqualityComparer<T> is used to compare keys.
Returns the last element of a sequence.
public static TSource Last<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
Returns the last element of a sequence that satisfies a
specified condition.
Returns the last element of a sequence, or a default value if
the sequence contains no elements.
public static TSource LastOrDefault<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
Returns the last element of a sequence that satisfies a
condition or a default value if no such element is found.
Returns an Int64 that represents the total number
of elements in a sequence.
public static long LongCount<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
Returns an Int64 that represents how many elements
in a sequence satisfy a condition.
Returns the maximum value in a generic sequence.
public static TResult Max<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TResult> selector)
Invokes a transform function on each element of a generic
sequence and returns the maximum resulting value.
Returns the maximum value in a sequence of nullable
Int32 values.
Invokes a transform function on each element of a sequence and
returns the maximum nullable Int32 value.
Returns the maximum value in a sequence of nullable
Int64 values.
Invokes a transform function on each element of a sequence and
returns the maximum nullable Int64 value.
Returns the maximum value in a sequence of nullable
Single values.
Invokes a transform function on each element of a sequence and
returns the maximum nullable Single value.
Returns the maximum value in a sequence of nullable
Double values.
public static double? Max<TSource>(this IEnumerable<TSource> source, Func<TSource, double?> selector)
Invokes a transform function on each element of a sequence and
returns the maximum nullable Double value.
Returns the maximum value in a sequence of nullable
Decimal values.
public static decimal? Max<TSource>(this IEnumerable<TSource> source, Func<TSource, decimal?> selector)
Invokes a transform function on each element of a sequence and
returns the maximum nullable Decimal value.
Returns the minimum value in a generic sequence.
public static TResult Min<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TResult> selector)
Invokes a transform function on each element of a generic
sequence and returns the minimum resulting value.
Returns the minimum value in a sequence of nullable
Int32 values.
Invokes a transform function on each element of a sequence and
returns the minimum nullable Int32 value.
Returns the minimum value in a sequence of nullable
Int64 values.
Invokes a transform function on each element of a sequence and
returns the minimum nullable Int64 value.
Returns the minimum value in a sequence of nullable
Single values.
Invokes a transform function on each element of a sequence and
returns the minimum nullable Single value.
Returns the minimum value in a sequence of nullable
Double values.
public static double? Min<TSource>(this IEnumerable<TSource> source, Func<TSource, double?> selector)
Invokes a transform function on each element of a sequence and
returns the minimum nullable Double value.
Returns the minimum value in a sequence of nullable
Decimal values.
public static decimal? Min<TSource>(this IEnumerable<TSource> source, Func<TSource, decimal?> selector)
Invokes a transform function on each element of a sequence and
returns the minimum nullable Decimal value.
Filters the elements of an IEnumerable based on a specified type.
public static IOrderedEnumerable<TSource> OrderBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
Sorts the elements of a sequence in ascending order according to a key.
public static IOrderedEnumerable<TSource> OrderBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, IComparer<TKey> comparer)
Sorts the elements of a sequence in ascending order by using a
specified comparer.
public static IOrderedEnumerable<TSource> OrderByDescending<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
Sorts the elements of a sequence in descending order according to a key.
public static IOrderedEnumerable<TSource> OrderByDescending<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, IComparer<TKey> comparer)
Sorts the elements of a sequence in descending order by using a
specified comparer.
Generates a sequence of integral numbers within a specified range.
Generates a sequence that contains one repeated value.
Inverts the order of the elements in a sequence.
public static IEnumerable<TResult> Select<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TResult> selector)
Projects each element of a sequence into a new form.
public static IEnumerable<TResult> Select<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, int, TResult> selector)
Projects each element of a sequence into a new form by
incorporating the element's index.
public static IEnumerable<TResult> SelectMany<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, IEnumerable<TResult>> selector)
Projects each element of a sequence to an IEnumerable<T>
and flattens the resulting sequences into one sequence.
public static IEnumerable<TResult> SelectMany<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, int, IEnumerable<TResult>> selector)
Projects each element of a sequence to an IEnumerable<T>,
and flattens the resulting sequences into one sequence. The
index of each source element is used in the projected form of
that element.
public static IEnumerable<TResult> SelectMany<TSource, TCollection, TResult>(this IEnumerable<TSource> source, Func<TSource, IEnumerable<TCollection>> collectionSelector, Func<TSource, TCollection, TResult> resultSelector)
Projects each element of a sequence to an IEnumerable<T>,
flattens the resulting sequences into one sequence, and invokes
a result selector function on each element therein.
public static IEnumerable<TResult> SelectMany<TSource, TCollection, TResult>(this IEnumerable<TSource> source, Func<TSource, int, IEnumerable<TCollection>> collectionSelector, Func<TSource, TCollection, TResult> resultSelector)
Projects each element of a sequence to an IEnumerable<T>,
flattens the resulting sequences into one sequence, and invokes
a result selector function on each element therein. The index of
each source element is used in the intermediate projected form
of that element.
public static bool SequenceEqual<TSource>(this IEnumerable<TSource> first, IEnumerable<TSource> second)
Determines whether two sequences are equal by comparing the
elements by using the default equality comparer for their type.
public static bool SequenceEqual<TSource>(this IEnumerable<TSource> first, IEnumerable<TSource> second, IEqualityComparer<TSource> comparer)
Determines whether two sequences are equal by comparing their
elements by using a specified IEqualityComparer<T>.
Returns the only element of a sequence, and throws an exception
if there is not exactly one element in the sequence.
public static TSource Single<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
Returns the only element of a sequence that satisfies a
specified condition, and throws an exception if more than one
such element exists.
Returns the only element of a sequence, or a default value if
the sequence is empty; this method throws an exception if there
is more than one element in the sequence.
public static TSource SingleOrDefault<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
Returns the only element of a sequence that satisfies a
specified condition or a default value if no such element
exists; this method throws an exception if more than one element
satisfies the condition.
Bypasses a specified number of elements in a sequence and then
returns the remaining elements.
public static IEnumerable<TSource> SkipWhile<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
Bypasses elements in a sequence as long as a specified condition
is true and then returns the remaining elements.
public static IEnumerable<TSource> SkipWhile<TSource>(this IEnumerable<TSource> source, Func<TSource, int, bool> predicate)
Bypasses elements in a sequence as long as a specified condition
is true and then returns the remaining elements. The element's
index is used in the logic of the predicate function.
Computes the sum of a sequence of nullable Int32 values.
Computes the sum of a sequence of nullable Int32
values that are obtained by invoking a transform function on
each element of the input sequence.
Computes the sum of a sequence of Int32 values.
Computes the sum of a sequence of Int32
values that are obtained by invoking a transform function on
each element of the input sequence.
Computes the sum of a sequence of nullable Int64 values.
Computes the sum of a sequence of nullable Int64
values that are obtained by invoking a transform function on
each element of the input sequence.
Computes the sum of a sequence of Int64 values.
Computes the sum of a sequence of Int64
values that are obtained by invoking a transform function on
each element of the input sequence.
Computes the sum of a sequence of nullable Single values.
Computes the sum of a sequence of nullable Single
values that are obtained by invoking a transform function on
each element of the input sequence.
Computes the sum of a sequence of Single values.
Computes the sum of a sequence of Single
values that are obtained by invoking a transform function on
each element of the input sequence.
Computes the sum of a sequence of nullable Double values.
Computes the sum of a sequence of nullable Double
values that are obtained by invoking a transform function on
each element of the input sequence.
Computes the sum of a sequence of Double values.
public static double? Sum<TSource>(this IEnumerable<TSource> source, Func<TSource, double?> selector)
Computes the sum of a sequence of Double
values that are obtained by invoking a transform function on
each element of the input sequence.
Computes the sum of a sequence of nullable Decimal values.
public static decimal Sum<TSource>(this IEnumerable<TSource> source, Func<TSource, decimal> selector)
Computes the sum of a sequence of nullable Decimal
values that are obtained by invoking a transform function on
each element of the input sequence.
Computes the sum of a sequence of Decimal values.
public static decimal? Sum<TSource>(this IEnumerable<TSource> source, Func<TSource, decimal?> selector)
Computes the sum of a sequence of Decimal
values that are obtained by invoking a transform function on
each element of the input sequence.
Returns a specified number of contiguous elements from the start
of a sequence.
public static IEnumerable<TSource> TakeWhile<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
Returns elements from a sequence as long as a specified condition is true.
public static IEnumerable<TSource> TakeWhile<TSource>(this IEnumerable<TSource> source, Func<TSource, int, bool> predicate)
Returns elements from a sequence as long as a specified condition is true.
The element's index is used in the logic of the predicate function.
public static IOrderedEnumerable<TSource> ThenBy<TSource, TKey>(this IOrderedEnumerable<TSource> source, Func<TSource, TKey> keySelector)
Performs a subsequent ordering of the elements in a sequence in
ascending order according to a key.
public static IOrderedEnumerable<TSource> ThenBy<TSource, TKey>(this IOrderedEnumerable<TSource> source, Func<TSource, TKey> keySelector, IComparer<TKey> comparer)
Performs a subsequent ordering of the elements in a sequence in
ascending order by using a specified comparer.
public static IOrderedEnumerable<TSource> ThenByDescending<TSource, TKey>(this IOrderedEnumerable<TSource> source, Func<TSource, TKey> keySelector)
Performs a subsequent ordering of the elements in a sequence in
descending order, according to a key.
public static IOrderedEnumerable<TSource> ThenByDescending<TSource, TKey>(this IOrderedEnumerable<TSource> source, Func<TSource, TKey> keySelector, IComparer<TKey> comparer)
Performs a subsequent ordering of the elements in a sequence in
descending order by using a specified comparer.
Creates an array from an IEnumerable<T>.
public static Dictionary<TKey, TSource> ToDictionary<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
Creates a Dictionary<T, U> from an
IEnumerable<T> according to a specified key
selector function.
public static Dictionary<TKey, TSource> ToDictionary<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer)
Creates a Dictionary<T, U> from an
IEnumerable<T> according to a specified key
selector function and key comparer.
public static Dictionary<TKey, TElement> ToDictionary<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector)
Creates a Dictionary<T, U> from an
IEnumerable<T> according to specified key
selector and element selector functions.
public static Dictionary<TKey, TElement> ToDictionary<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer)
Creates a Dictionary<T, U> from an
IEnumerable<T> according to a specified key
selector function, a comparer, and an element selector function.
Creates a List<T> from an IEnumerable<T>.
public static ILookup<TKey, TSource> ToLookup<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
Creates a Lookup<T, U> from an
IEnumerable<T> according to a specified key
selector function.
public static ILookup<TKey, TSource> ToLookup<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer)
Creates a Lookup<T, U> from an
IEnumerable<T> according to a specified key
selector function and a key comparer.
public static ILookup<TKey, TElement> ToLookup<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector)
Creates a Lookup<T, U> from an
IEnumerable<T> according to specified key
and element selector functions.
public static ILookup<TKey, TElement> ToLookup<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer)
Creates a Lookup<T, U> from an
IEnumerable<T> according to a specified key
selector function, a comparer and an element selector function.
public static IEnumerable<TSource> Union<TSource>(this IEnumerable<TSource> first, IEnumerable<TSource> second)
Produces the set union of two sequences by using the default
equality comparer.
public static IEnumerable<TSource> Union<TSource>(this IEnumerable<TSource> first, IEnumerable<TSource> second, IEqualityComparer<TSource> comparer)
Produces the set union of two sequences by using a specified
IEqualityComparer<T>.
public static IEnumerable<TSource> Where<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
Filters a sequence of values based on a predicate.
public static IEnumerable<TSource> Where<TSource>(this IEnumerable<TSource> source, Func<TSource, int, bool> predicate)
Filters a sequence of values based on a predicate.
Each element's index is used in the logic of the predicate function.