The translation awaitis that, firstly, it GetAwaiter()is called on the expected object (in your case a Task). He then does some other complicated things, but here they are not relevant:
await MyClass?.Job();
Compiles:
var awaiter = MyClass?.Job().GetAwaiter();
Since it Task.GetAwaiter()is an instance method, and you call it with null Task, you get NullReferenceException.
, await a null , GetAwaiter() , null:
public class NullAwaitable { }
public static class Extensions
{
public static TaskAwaiter GetAwaiter(this NullAwaitable _)
=> Task.CompletedTask.GetAwaiter();
}
public class MethodClass
{
public NullAwaitable Job() => new NullAwaitable();
}
MethodClass MyClass = null;
await MyClass?.Job();