I wrote this simple snippet today, and thought I’d share:
public static IEnumerable<int> Until(this int from, int to)
{
for (int i = from; i <= to; i++)
{
yield return i;
}
}
Its purpose is to return number ranges:
IEnumerable<int> firstTen = 1.Until(10);
foreach (int i in firstTen)
{
Console.Write(i + " ");
}
Which outputs the following:
1 2 3 4 5 6 7 8 9 10