I have probably worked myself into a rather immature confusion. Please refer the code below (console app)
namespace Tasks101
{
class Program
{
static void Main(string[] args)
{
Program p = new Program();
var x = p.Blah();
}
private async Task Blah()
{
await Task.Delay(TimeSpan.FromSeconds(3)).ConfigureAwait(false);
}
private async void ReturnsVoid()
{
await Task.Delay(TimeSpan.FromSeconds(3)).ConfigureAwait(false);
}
private void Nothing()
{
}
}
}
My question is that in Blah()
method I don't have any explicit return statement yet when this executes
var x = p.Blah();
the type of x
is Task
. Again I have no return statement in ReturnsVoid
method but that compiles too.
So the questions are
- What is returning a
Task
from theBlah
method without my having areturn
statement there and why is that same thing not returning anything fromReturnsVoid
method. - How do I control what gets returned from the
Blah
method? What if I had two await statements there one after the other?