Task<T>

Represents an asynchronous operation that produces a result of type T. The foundation of async/await in .NET.

Syntax

csharp
Task<T> method();
Task method(); // for void async

Example

csharp
async Task<int> ComputeAsync() {
  await Task.Delay(1000);
  return 42;
}

// Run multiple tasks in parallel:
var tasks = urls.Select(url => client.GetStringAsync(url));
var results = await Task.WhenAll(tasks);