Last active
February 20, 2017 15:15
-
-
Save onionmk2/e65878d9cee86d49cf22cb353ff3a0bf to your computer and use it in GitHub Desktop.
yield and foreach
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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