Created
September 30, 2019 00:46
-
-
Save codehaks/62fbe2cc1108bf69f50c8d816cbba7be to your computer and use it in GitHub Desktop.
IAsyncEnumerable compare
This file contains 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; | |
using System.Threading.Tasks; | |
namespace PhotoSlash | |
{ | |
class Program | |
{ | |
static async Task Main(string[] args) | |
{ | |
Console.WriteLine("Hello World!"); | |
await foreach (var number in GenerateNumbers()) | |
{ | |
Console.WriteLine(number); | |
} | |
foreach (var number in await GenerateNumbers2()) | |
{ | |
Console.WriteLine(number); | |
} | |
} | |
internal static async IAsyncEnumerable<int> GenerateNumbers() | |
{ | |
var x = 5; | |
for (int i = 0; i < 50; i++) | |
{ | |
if (i % 10 == 0) | |
{ | |
await Task.Delay(3000); | |
} | |
yield return 5; | |
} | |
} | |
internal static async Task<IEnumerable<int>> GenerateNumbers2() | |
{ | |
var numbers = new List<int>(); | |
for (int i = 0; i < 50; i++) | |
{ | |
if (i % 10 == 0) | |
{ | |
await Task.Delay(3000); | |
} | |
numbers.Add(i); | |
} | |
return numbers; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment