I have checked other postings including Group by variable integer range using Linq
but i have not found anything that is similar to my question...I am trying to group into integer ranges where the integer sequence is discontinuous. For example, if i have a set of continuous integers from 1-100 and then my set skips 101, i would want to create a record that takes the date from record #1 and #100, where the date from record #1 is the begin date and #100 is the end date.
Each range of continuous integers creates a new record to add to a list of records that indicate the date at the start and end of the range. if the range contains only one integer value (e.g. the integer ranges go from 1-100, 102, and 104-200) the single integer range would have the same start and end date.
Any suggestions?
Here's a sample class I created that might help. It converts a sequence of integers into a set of ranges. The code works in LINQPad.
You can make an extension method that will do this:
Usage:
Output:
I don't know if you'd be able to do this using the provided LINQ functions, but the following function:
used as follows:
may fit the bill.