Skip to content

Instantly share code, notes, and snippets.

@kuanyingchou
Last active August 29, 2015 14:04
Show Gist options
  • Save kuanyingchou/d38360ec58e629f8d3f5 to your computer and use it in GitHub Desktop.
Save kuanyingchou/d38360ec58e629f8d3f5 to your computer and use it in GitHub Desktop.
class Range : IEnumerable
{
int _start;
int _end;
int _step;
public Range(int start, int end = int.MaxValue)
{
_start = start;
_end = end;
_step = start < end ? 1 : -1;
}
public IEnumerator GetEnumerator()
{
int current = _start;
while (_step > 0 ? current <= _end : current >= _end)
{
yield return current;
current += _step;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment