有没有为(T,INT)凡和选择重载一个LINQ语法? [英] Is there a LINQ syntax for the (T, int) overloads of Where and Select?

查看:83
本文介绍了有没有为(T,INT)凡和选择重载一个LINQ语法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

查询

 变种Q =从收集
ELEM哪里someCondition(ELEM)
选择ELEM;



转换为



 变种q = collection.Where(ELEM => someCondition(ELEM)); 



有没有将转化以下?


$一个LINQ语法b $ b

 变种q = collection.Where((ELEM,指数)=> someCondition(ELEM,指数)); 


解决方案

没有有一个为没有LINQ的语法。



一个简单的解决方法可能是:

 变种q =从ELEM在collection.Select((X,I)=>新建{X,I})
,其中someCondition(elem.x,elem.i)
选择elem.x;


The query

var q = from elem in collection
        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;

这篇关于有没有为(T,INT)凡和选择重载一个LINQ语法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆