I'm new to C# asynchronous programming, sorry if my question sounds dumb. Below is some code:
static async Task Main(string[] args) {
var result = TestMethod(false); //result is still Task<string> rather than string
}
public static async Task<string> TestMethod(bool check) {
if (check) {
await Task.Delay(8000);
return "Hello World";
} else {
return "Goodbye World"; // no await in else statement
}
}
So there is no await in TestMethod's else statement, how does the code still compile? from my understanding, each possibile path should contain a await statement?
And result is still Task<string> rather than string, but the executation path only reach else statment which returns a string directly, how come result is still a task?