Last active
October 25, 2019 17:49
-
-
Save peterthorsteinson/d8d558c4d3c82be3aa5c6c8dbf0e9454 to your computer and use it in GitHub Desktop.
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
using System; | |
using System.Collections.Generic; | |
class Program | |
{ | |
static void Main() | |
{ | |
{ | |
var nums = GetArrayOfFirstTenIntegers(); | |
foreach (int n in nums) | |
{ | |
Console.WriteLine(n); | |
} | |
} | |
Console.WriteLine(); | |
{ | |
var nums = GetArrayOfFirstTenIntegersYield(); | |
foreach (int n in nums) | |
{ | |
Console.WriteLine(n); | |
} | |
} | |
} | |
static IEnumerable<int> GetArrayOfFirstTenIntegers() | |
{ | |
Console.WriteLine("GetArrayOfFirstTenIntegers called"); | |
List<int> nums = new List<int>(); | |
for (int num = 0; num <= 5; num++) | |
{ | |
Console.WriteLine("###"); | |
nums.Add(num); | |
} | |
return nums; | |
} | |
static IEnumerable<int> GetArrayOfFirstTenIntegersYield() | |
{ | |
Console.WriteLine("GetArrayOfFirstTenIntegersYield called"); | |
for (int num = 0; num <= 5; num++) | |
{ | |
Console.WriteLine("***"); | |
yield return num; | |
} | |
} | |
} |
Author
peterthorsteinson
commented
Oct 25, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment