The async keyword marks a method as asynchronous, allowing it to run operations without blocking the main thread. It enables the use of await inside the method.
Click to reveal answer
beginner
What is the purpose of the await keyword?
await pauses the execution of an async method until the awaited task completes, without blocking the thread. It helps write asynchronous code that looks like synchronous code.
Click to reveal answer
intermediate
Can an async method return void?
Yes, but only for event handlers. Normally, async methods return Task or Task<T> to allow callers to await them and handle exceptions.
Click to reveal answer
intermediate
What happens if you forget to use await inside an async method?
The method will run synchronously until it hits an awaited task. If you don't use await, the method may complete early and not wait for asynchronous operations, causing bugs.
Click to reveal answer
beginner
Why is using async and await better than blocking calls?
They keep the app responsive by not blocking threads. This is like waiting for a friend without stopping everything else you do, improving performance and user experience.
Click to reveal answer
What keyword do you use to mark a method as asynchronous in C#?
Athread
Bawait
Ctask
Dasync
✗ Incorrect
The async keyword marks a method as asynchronous.
What does the await keyword do?
ABlocks the thread until the task finishes
BPauses the async method without blocking the thread
CStarts a new thread
DCancels a running task
✗ Incorrect
await pauses the async method but does not block the thread.
Which return type is common for async methods?
ATask or Task<T>
Bint
Cstring
Dvoid
✗ Incorrect
Async methods usually return Task or Task<T>.
What happens if you call an async method but do not use await?
AThe method runs synchronously and waits
BThe program crashes
CThe method runs asynchronously but caller does not wait
DThe method is ignored
✗ Incorrect
Without await, the caller does not wait for the async method to finish.
Why should you avoid blocking calls in UI applications?
AThey freeze the UI and make it unresponsive
BThey keep the UI responsive
CThey improve performance
DThey use less memory
✗ Incorrect
Blocking calls freeze the UI, making the app unresponsive.
Explain how async and await work together in C# to keep applications responsive.
Think about waiting for a task without stopping everything else.
You got /4 concepts.
Describe the common return types of async methods and why they are important.
Consider how the caller knows when the async work is done.
You got /5 concepts.
Practice
(1/5)
1. What is the main purpose of the async keyword in C#?
easy
A. To make a method run faster by using multiple threads automatically
B. To mark a method that can run asynchronously without blocking the caller
C. To declare a method that returns void only
D. To pause the execution of a method until a task completes
Solution
Step 1: Understand the role of async
The async keyword marks a method so it can run asynchronously, allowing other work to continue without waiting.
Step 2: Differentiate from other options
It does not automatically make code faster or use multiple threads, nor does it pause execution by itself.
Final Answer:
To mark a method that can run asynchronously without blocking the caller -> Option B
Quick Check:
async marks asynchronous methods = A [OK]
Hint: Async marks methods that run without blocking [OK]
Common Mistakes:
Thinking async makes code multithreaded automatically
Confusing async with pausing execution
Believing async only works with void methods
2. Which of the following is the correct way to declare an asynchronous method that returns a string in C#?
easy
A. public string async GetData()
B. public async string GetData()
C. public Task async<string> GetData()
D. public async Task<string> GetData()
Solution
Step 1: Recall async method return types
Async methods that return a value must return Task<T>, where T is the return type, here string.
Step 2: Check syntax correctness
public async Task<string> GetData() correctly uses async Task<string>. Other options have wrong order or missing Task.
Final Answer:
public async Task<string> GetData() -> Option D
Quick Check:
Async methods returning values use Task<T> = A [OK]
Hint: Async methods returning values use Task<T> type [OK]
Common Mistakes:
Placing async after return type
Returning just string instead of Task<string>
Using async keyword incorrectly in method signature
3. What will be the output of the following C# code?
async Task<int> GetNumberAsync() { await Task.Delay(100); return 5; } async Task Main() { var result = await GetNumberAsync(); Console.WriteLine(result); }
medium
A. 5
B. 0
C. Task
D. Compilation error
Solution
Step 1: Understand async method behavior
The method GetNumberAsync waits 100ms then returns 5 asynchronously.
Step 2: Await the result and print
The Main method awaits GetNumberAsync and prints the returned value, which is 5.
Final Answer:
5 -> Option A
Quick Check:
Await returns method result = 5 [OK]
Hint: Await unwraps async result to actual value [OK]
Common Mistakes:
Expecting Task object printed instead of value
Ignoring await causing wrong output
Thinking async delays block main thread
4. Identify the error in this code snippet:
async Task<int> CalculateAsync() { return 10; } void Main() { var result = CalculateAsync(); Console.WriteLine(result); }
medium
A. Missing await keyword when calling CalculateAsync
B. CalculateAsync should return int, not Task<int>
C. Main method must be async to call CalculateAsync
D. CalculateAsync cannot return a value
Solution
Step 1: Analyze method call and return type
CalculateAsync returns a Task<int>, but Main calls it without await, so result is a Task, not int.
Step 2: Understand how to get actual value
To get the int value, await must be used, but Main is not async, so this is a problem.
Final Answer:
Missing await keyword when calling CalculateAsync -> Option A
Quick Check:
Call async method with await = C [OK]
Hint: Always await async calls to get results [OK]
Common Mistakes:
Calling async method without await
Expecting async method to return direct value
Making Main async without proper signature
5. You want to run two independent async tasks and get their results as soon as both finish. Which code correctly does this in C#?
hard
A. var result1 = await Task1(); var result2 = await Task2();
B. var result1 = Task1().Result; var result2 = Task2().Result;
C. var task1 = Task1(); var task2 = Task2(); var result1 = await task1; var result2 = await task2;
D. await Task.WhenAll(Task1(), Task2()); var result1 = Task1().Result; var result2 = Task2().Result;
Solution
Step 1: Understand running tasks concurrently
Starting both tasks without awaiting immediately lets them run in parallel.
Step 2: Await both tasks after starting
Awaiting each task after starting both ensures you wait for both to finish and get results efficiently.
Step 3: Analyze other options
var result1 = await Task1(); var result2 = await Task2(); awaits sequentially, running tasks one after another. var result1 = Task1().Result; var result2 = Task2().Result; blocks synchronously causing deadlocks. await Task.WhenAll(Task1(), Task2()); var result1 = Task1().Result; var result2 = Task2().Result; awaits but then calls Result again, causing redundant calls.
Final Answer:
var task1 = Task1(); var task2 = Task2(); var result1 = await task1; var result2 = await task2; -> Option C
Quick Check:
Start tasks first, then await both = B [OK]
Hint: Start tasks first, then await both to run concurrently [OK]
Common Mistakes:
Awaiting tasks one by one causing sequential execution
Using .Result causing blocking and deadlocks
Calling tasks multiple times causing duplicate work
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.