我是一个LINQ新手,正在尝试使用它来获得以下内容:
我有一个int列表:
List<int> intList = new List<int>(new int[]{1,2,3,3,2,1});
现在,我想使用LINQ比较前三个元素索引范围0-2和后三个索引范围3-5的总和。我尝试了LINQ Select和Take扩展方法以及SelectMany方法,但我不知道如何表示如下内容
(from p in intList
where p in Take contiguous elements of intList from index x to x+n
select p).sum()
我也查看了包含扩展方法,但这并不能得到我想要的结果。有什么建议吗?谢谢。
https://stackoverflow.com/questions/1042087
复制相似问题