Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How get range of numbers [duplicate]

Tags:

c#

I have a interval of number [1, 20].

I want a method which returns me range of number available if I decide to ban range [15, 18]. My method should return me a list containing [1,15] and [18, 20]

Range object could looks like something like that

public class Range
{
     int Start {get;set;}
     int End {get;set;}
}

Any help would be appreciated.

like image 569
John Avatar asked Sep 15 '11 18:09

John


1 Answers

What about this?

IEnumerable<int> range = Enumerable.Range(1, 20);
IEnumerable<int> banned = Enumerable.Range(15, 4);
return range.Except(banned);

The Enumerable class already has a static method which will return a range of values for you - might be simpler to just use those semantics.

like image 196
matt Avatar answered Oct 24 '22 04:10

matt