I need a helper method to add axis labels to the chart. I don’t want to add a label to every point along the axis that matters on the chart because it’s too busy. Therefore, I need to regularly extract samples. So far, I have come up with the following method that meets the requirements, but I think there should be an easier way in Linq to accomplish this. Can anyone think of a way to make this more concise (n represents the total number of samples I want to return)?
public static List<T> Sample<T>(this List<T> list, int n)
{
var samples = new List<T>();
var divisor = list.Count/n;
for (var i = 0; i < list.Count; i++)
if (samples.Count == i/divisor)
samples.Add(list[i]);
return samples;
}
source
share