3

I want to know if there is an already made data type for ranges. It'll must have capability more than just representing a range of numbers, but also to have a value to a range and to be able to intersect ranges, to explain better I'll show what I'm expecting with C# code as if there was this kind of data type.

        RangeCollection rc = new RangeCollection();
        //rc.Add(new Range(from, to, value));
        rc.Add(new Range(1, 4, 1));
        rc.Add(new Range(3, 6, 2));
        Console.WriteLine(rc[1]); // output is: 1
        Console.WriteLine(rc[4]); //output is: [1,2]

I know I can do it myself, but I want to know if there is something already existing which is similar or partially like this. Thanks!

AlonMln
  • 227
  • 1
  • 3
  • 10
  • 3
    See this: http://www.codeproject.com/Articles/19028/Building-a-Generic-Range-class – Victor Zakharov Apr 16 '14 at 13:41
  • Hi Neolisk, i've seen the question, and it does not meet all of my needs (it doesn't have a value nor can it intersect two ranges). I'm checking out the code project like no, so thanks! – AlonMln Apr 16 '14 at 13:45
  • 1
    Regarding the above SO answer - should be easy to extend from that point, like 1 line per each intersect, union etc. Or just use the CodeProject one - that is fairly rich already. – Victor Zakharov Apr 16 '14 at 13:48

0 Answers0