Click here to Skip to main content
15,885,213 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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)
Posted
Updated 13-Oct-16 22:58pm

1 solution

You can use the IEnumerable<T>.Where(Func<T, int, bool>) extension:

results = rows.Where((r,i)=>i % 15 == 0);
 
Share this answer
 
Comments
Midi_Mick 14-Oct-16 5:00am    
or, for a faster result, every 16th element could be done with a bitwise operator rather than the modulus operator i.e. (i & 15) == 0
Herman<T>.Instance 14-Oct-16 5:29am    
you're a legend!
Maciej Los 14-Oct-16 16:57pm    
5ed!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900