Google News
logo
C# - Interview Questions
Explain Async and Await in C#?
Async and Await keywords are mostly used for creating asynchronous methods in C#. Usage of the same is shown through an example :
public async Task>CalculateCount()
{
await Task.Delay(2000);
return 1;
}
public async task mytestmethod()
{
Task> count = CalculateCount();
int result = await count;
}
In the above-given code async keyword is used for method declaration. The Count is of a task type int which calls the method CalculateCount(). CalculateCount() starts execution and calculates something.
Advertisement