Linq:根据间隔获取结果集的一部分 [英] Linq: get part of resultset based on an interval
问题描述
嗨伙计,
我正在写一个ASP.NET网站,在google地图上显示全球坐标/地理位置。
下面该地图我想显示一个图表,显示属于该GeoLocation的一些值。由于它处理数十万个(它是带有附加数据的GMAP折线。附加数据应该显示在图表中),因此几乎不可能为此创建图形(限制32000条记录)。
如何创建一个结果集,其中包含完整的c#datatable中的任何第n行
linq查询可以帮助我从原始的150,000行中获得最多10,000行。因此,跳过15行的间隔应该可以解决问题。
在结果集中第1,16,31 ......等等应该设置。
我尝试过的事情:
我用谷歌搜索是否可行但是跳过linq只会移动指针然后返回到给定的行,然后返回该组的其余部分(150,000 - 15不想要我)
Hi Folks,
I am writing an ASP.NET website which show global coordinates/geolocation on a google map.
Below that map I want to show a graph which displays some values that belong to that GeoLocation. Since it handles hundreds of thousands (it is a GMAP polyline with additional data. That additional data should show up in a graph) of points it is pretty impossible to create a graph for that (limit 32000 records).
How can I create a result set that holds any nth row from the full c# datatable
Can a linq query help me out to have a maximum of 10,000 rows from the original 150,000 rows. So a skip interval of 15 rows should do the trick.
In the resultset row 1, 16, 31.... and so should be set.
What I have tried:
I have Googled to see if that is possible but skip in linq only moves the pointer to a given row and the remainder of that set is then returned (150,000 - 15 is not want I want)
推荐答案
您可以使用IEnumerable< T> .Where (Func< T,int,bool>)扩展名:
You can use the IEnumerable<T>.Where(Func<T, int, bool>) extension:
results = rows.Where((r,i)=>i % 15 == 0);
这篇关于Linq:根据间隔获取结果集的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!