Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linq Index question

Tags:

c#

linq

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...
like image 876
Rejk Avatar asked Oct 24 '25 22:10

Rejk


1 Answers

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 where clause translates to an invocation of Where<TSource>(IEnumerable<TSource>, Func<TSource, Boolean>).

like image 197
AakashM Avatar answered Oct 26 '25 12:10

AakashM