I have a situation that is well explained in this question:
I need a C# implementation (a collection maybe) that takes a list of ranges (of ints) and do the union of them.
Then I need to iterate through all ints in this collection (also numbers between ranges)
Are there any library/implementation so that I don’t have to rewrite everything by myself?
The simplest thing that comes to my mind is to use Enumerable.Range, and then treat the different IEnumerable with standard linq operators. Something like:
Obviously you can use Union and Intersect as well… clearly you can also put your ranges in a
List<IEnumerable<int>>or something similar and then iterate over the elements for producing a single list of the elements: