我可以用索引写这样的代码吗
var someArray = new List<int>(){1,2,3,4,5};
var resultArray = someArray.Where((num, index) => index % 2 == 0);
喜欢
var resultArray = from num in someArray...
最佳答案
我想你是在问“我可以使用查询表达式语法来获得提供项目索引的Where
的重载,就像我可以使用流畅的方法一样-链接语法”。
答案是否定的。
如 the no-index-parameter overload of Where
的文档中所示:
In query expression syntax, a
where
clause translates to an invocation ofWhere<TSource>(IEnumerable<TSource>, Func<TSource, Boolean>)
.
关于c# - Linq索引问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7204872/