Still going through a learning phase with C# and ran into a question I needed help with. Considering the following code:
private async Task<String> PrintTask()
{
await Task.Delay(3000);
return "Hello";
}
private async void SayHelloTwice()
{
string firstHello = await PrintTask();
string secondHello = await PrintTask();
Console.WriteLine(firstHello);
Console.WriteLine(secondHello);
}
Right now SayHelloTwice() will take 6 seconds to complete. However, I want the retrieval tasks to be ran in parallel so that it only takes 3 seconds to complete. How would I refactor my code to achieve that? Thanks!