Can I write code like this with index
var someArray = new List<int>(){1,2,3,4,5};
var resultArray = someArray.Where((num, index) => index % 2 == 0);
like
var resultArray = from num in someArray...
I suppose you are asking "can I use query expression syntax to get at the overload of Where that provides the item index, in the way that I can using fluent method-chaining syntax".
The answer is no.
As seen in the docs for the no-index-parameter overload of Where :
In query expression syntax, a
whereclause translates to an invocation ofWhere<TSource>(IEnumerable<TSource>, Func<TSource, Boolean>).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With