Challenge - 5 Problems
Async Return Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of async method returning Task
What is the output of this C# program when run?
C Sharp (C#)
using System; using System.Threading.Tasks; class Program { static async Task<int> GetNumberAsync() { await Task.Delay(100); return 42; } static async Task Main() { int result = await GetNumberAsync(); Console.WriteLine(result); } }
Attempts:
2 left
💡 Hint
Remember that awaiting an async method unwraps the Task and gives the actual return value.
✗ Incorrect
The method GetNumberAsync returns a Task. Awaiting it in Main unwraps the Task and returns the integer 42, which is printed.
❓ Predict Output
intermediate2:00remaining
Return type of async method without Task
What happens when you try to compile and run this code?
C Sharp (C#)
using System; using System.Threading.Tasks; class Program { static async Task<int> GetNumberAsync() { await Task.Delay(100); return 10; } static async Task Main() { int result = await GetNumberAsync(); Console.WriteLine(result); } }
Attempts:
2 left
💡 Hint
Async methods must return Task, Task, or void (rarely).
✗ Incorrect
Async methods cannot have return type int directly. They must return Task for async methods returning int values.
🔧 Debug
advanced2:00remaining
Why does this async method return null?
Consider this code snippet. Why does the output print "Result is: " with no number after it?
C Sharp (C#)
using System; using System.Threading.Tasks; class Program { static async Task<string> GetTextAsync() { await Task.Delay(50); string text = null; return text; } static async Task Main() { string result = await GetTextAsync(); Console.WriteLine($"Result is: {result}"); } }
Attempts:
2 left
💡 Hint
Check what value the async method returns and how null strings print.
✗ Incorrect
The method returns a null string. When printing with interpolation, null prints as empty, so output is "Result is: " with nothing after.
❓ Predict Output
advanced2:00remaining
Output of async method returning Task without await
What is the output of this program?
C Sharp (C#)
using System; using System.Threading.Tasks; class Program { static async Task DoWorkAsync() { Console.WriteLine("Start"); // No await here Console.WriteLine("End"); } static async Task Main() { await DoWorkAsync(); } }
Attempts:
2 left
💡 Hint
Async methods can run synchronously if no await is present.
✗ Incorrect
Since DoWorkAsync has no await, it runs synchronously printing Start then End immediately.
🧠 Conceptual
expert2:00remaining
What is the type of the value returned by an async method with signature 'async Task'?
Given an async method declared as 'async Task ComputeAsync()', what is the type of the value you get when you await this method?
Attempts:
2 left
💡 Hint
Await unwraps the Task and gives the inner value.
✗ Incorrect
Awaiting a Task returns the int value inside the Task.