Created
August 4, 2018 22:00
-
-
Save shawn-hurley/03d1206208e99923fcdf972223cb4644 to your computer and use it in GitHub Desktop.
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.Linq; | |
using System.Threading.Tasks; | |
namespace c_sharp_example | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("Hello World!"); | |
List<Task<int>> l = new List<Task<int>>(); | |
List<int> ints = new List<int>{1, 2, 3, 4, 5}; | |
foreach(int i in ints) | |
{ | |
l.Add(SleepThenReturnAsync(i)); | |
} | |
newSleepMethodForReallyLongTime(); | |
List<int> m = new List<int>(); | |
foreach (Task<int> t in l) | |
{ | |
m.Add(t.Result); | |
} | |
foreach (int i in m) | |
{ | |
Console.WriteLine(i); | |
} | |
} | |
static async Task<int> SleepThenReturnAsync(int i) | |
{ | |
Console.WriteLine("x: "+ i + " is sleeping"); | |
await Task.Delay(5000); | |
return i; | |
} | |
static void newSleepMethodForReallyLongTime() | |
{ | |
System.Threading.Thread.Sleep(15000); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment