I have a list of ranges. Each range has a from and to value, meaning the value can be between that range. For eample if range is (1,4)., the values can be 1,2,3 and 4. Now, I need to find the distinct values in a given list of range. Below is the sample code.
class Program
{
static void Main(string[] args)
{
List<Range> values = new List<Range>();
values.Add(new Range(1, 2));
values.Add(new Range(1, 3));
values.Add(new Range(1, 4));
values.Add(new Range(3, 5));
values.Add(new Range(7, 10));
values.Add(new Range(7, 8));
// Expected Output from the range of values
//1,2,3,4,5,7,8,9,10
}
}
class Range
{
public Range(int _form, int _to)
{
from = _from;
to = _to;
}
private int from;
public int From
{
get { return from; }
set { from = value; }
}
private int to;
public int To
{
get { return to; }
set { to = value; }
}
}
I can loop through every range and find the distinct values. but if some one can give an effieient approach, it would be helpful.
1 Answer