Assume I have a method that has void
return type and that I need to await
on an operation in this method.
public void someOperation()
{
//dostuff
var res = await someOtherOperation();
//do some other stuff that needs res.
}
When I tried to compile this code I got the error saying someOperation
has to be declare async
. I don't understand why. I understand why it would if the method had a return value, but not here when it's void
. or even in the case when the awaiting operation has no effect on the return value of method.
This has already been asked as a part of this question but I didn't find the answer I was looking for. This guy merely mentions:
The async keyword enables the await keyword. So any method using await must be marked async.
- First of all, I'm not sure what it means that
async
keyword enablesawait
keyword. - And secondly, restating my question, I'm not sure why it is required?