For a report I had to show a list of items (ID's). Instead of showing them all, they wanted to show consecutive items separated by a dash. Just like the way you would use print pages in Word for example. In the print dialog you can say 1-5, 8 to indicate pages 1, 2, 3, 4, 5, 8. The code shows how you can do this with Linq in a single (but long) line.
I've created the ConsecutiveGroup
class for it, because both the standard KeyValuePair
and Tuple
classes I wanted to use at first have read-only properties.
Feel free to comment or question.