Async / await · interview question
In what order are the letters printed? (Each WriteLine prints one letter per line.)
What does this code output?Hard
Console.WriteLine("A");
var task = GetAsync();
Console.WriteLine("C");
Console.WriteLine(await task);
static async Task<string> GetAsync()
{
Console.WriteLine("B");
await Task.Delay(100);
Console.WriteLine("D");
return "E";
}Answer and explanation
Correct answer
A. A B C D E
Why
Calling an async method runs it synchronously up to the first incomplete await, so B prints right after A. The method then returns a task, the caller prints C, and when the delay finishes D prints and the task completes with E.
Test yourself on Async / await
A free test with instant, explained results. No account needed.