collections - c# implementation get range of values and union of these ranges -


i have situation explained in question:

range intersection / union

i need c# implementation (a collection maybe) takes list of ranges (of ints) , union of them. need iterate through ints in collection (also numbers between ranges) there library/implementation don't have rewrite myself?

the simplest thing comes mind use enumerable.range, , treat different ienumerable standard linq operators. like:

var list = enumerable.range(1, 5) .concat(enumerable.range(7, 11)) .concat(enumerable.range(13, 22))  foreach(var number in list)   // 

obviously can use union , intersect well... can put ranges in list<ienumerable<int>> or similar , iterate on elements producing single list of elements:

var ranges = new list<ienumerable<int>>  {      enumerable.range(1, 5),      enumerable.range(7, 11),      enumerable.range(10, 22)  }; var unionofranges = enumerable.empty<int>();  foreach(var range in ranges)     unionofranges = unionofranges.union(range);  foreach(var item in unionofranges)     // 

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -