Skip to content

Instantly share code, notes, and snippets.

@onionmk2
Last active February 20, 2017 15:15
Show Gist options
  • Select an option

  • Save onionmk2/e65878d9cee86d49cf22cb353ff3a0bf to your computer and use it in GitHub Desktop.

Select an option

Save onionmk2/e65878d9cee86d49cf22cb353ff3a0bf to your computer and use it in GitHub Desktop.
yield and foreach
internal class Program
{
private static void Main(string[] args)
{
var ints = MyIEnumrable.FromTo(0, 10);
foreach (var i in ints)
Console.WriteLine("{0}", i);
}
}
internal class MyIEnumrable
{
public static IEnumerable<int> FromTo(int from, int to)
{
while (from <= to)
yield return from++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment