When I ran the following code (which I was asked during a C# interview), it did not output anything.
Can somebody explain this behavior?
class Program {
private static string result;
static void Main() {
SaySomething();
Console.WriteLine(result);
}
static async Task<string> SaySomething() {
await Task.Delay(5);
result = "Hello world!";
return “Something”;
}
}
I thought this method should output result
, because I am calling
Console.WriteLine(result);
after the SaySomething()
method call completed