I’ve got an IEnumerable<T> containing a list of data elements with consistent intervals in one of the properties:
List<Interval> list = new List<Interval>
{
new Interval{ TIME_KEY = 600},
new Interval{ TIME_KEY = 605},
new Interval{ TIME_KEY = 615},
new Interval{ TIME_KEY = 620},
new Interval{ TIME_KEY = 630}
};
How can I query this list (using Linq, preferably), to get a List that looks like this:
List<Interval> list = new List<Interval>
{
new Interval{ TIME_KEY = 610},
new Interval{ TIME_KEY = 625}
};
?
EDIT: I will probably know what the interval distance is supposed to be, but if there’s a way to determine it by examing the data, that would be a huge bonus!
EDIT: changed to numeric values
Have a look at this question for an extension method which selects consecutive values. From there, you could do something like:
(Somewhat pseudocode, but I hope you see where I’m going.)
However, that would only generate one element when it’s missing… if you went from 0 to 20, it wouldn’t generate 5, 10, 15.
To put some meat on Henk’s second suggestion: