开发者

Is there a LINQ syntax for the (T, int) overloads of Where and Select?

The query

var q = from elem in collection
   开发者_JS百科     where someCondition(elem)
        select elem;

translates to

var q = collection.Where(elem => someCondition(elem));

Is there a LINQ syntax that would translate to the following?

var q = collection.Where((elem, index) => someCondition(elem, index));


No there's no LINQ syntax for that.

A simple work-around could be:

var q = from elem in collection.Select((x,i) => new {x,i})
        where someCondition(elem.x,elem.i)
        select elem.x;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜