Skip to content

Instantly share code, notes, and snippets.

@sinuj31
Forked from TryJSIL/Yield.cs
Created November 19, 2014 05:22
Show Gist options
  • Save sinuj31/07f7080d7de9a49a86aa to your computer and use it in GitHub Desktop.
Save sinuj31/07f7080d7de9a49a86aa to your computer and use it in GitHub Desktop.
Generators
using System;
using System.Collections;
using System.Collections.Generic;
public static class Program {
public static IEnumerable<int> OneToNine {
get {
for (int i = 0; i < 10; i++)
yield return i;
}
}
public static void Main (string[] args) {
foreach (var i in OneToNine)
Console.WriteLine("{0}", i);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment