What is async/await in C#?
Answer
async/await is C#'s mechanism for writing asynchronous code that reads like synchronous code, built on the Task-based asynchronous pattern (TAP). async keyword marks a method as asynchronous — it can contain await expressions. await suspends the method at that point, releasing the thread to do other work while the awaited operation completes. Example: public async Task<string> GetDataAsync() { var response = await httpClient.GetAsync(url); return await response.Content.ReadAsStringAsync(); }. The method returns a Task (or Task<T>). Key rules: (1) Async all the way — don't mix sync and async (avoid .Result or .Wait() which can deadlock). (2) Use ConfigureAwait(false) in library code. (3) ValueTask<T> for hot paths where the result is often synchronously available. (4) Avoid async void (exceptions are unobservable) — except for event handlers.