It is a common question about why do we need to mark methods as async
. We have already mentioned iterator methods in C# and the yield
keyword. This is very similar to async
/await
, and yet we do not need to mark iterator methods with any modifier. The C# compiler is able to determine that it is an iterator method when it meets the yield return
or yield break
operators inside such a method. So the question is, why is it not the same with await
and the asynchronous methods?
The reason is that asynchrony support was introduced in the latest C# version, and it is very important not to break any legacy code while changing the language. Imagine if any code used await
as a name for a field or variable. If C# developers make await
a keyword without any conditions, this old code will break and stop compiling. The current approach guarantees that if we do not mark a method with async
, the old code will continue to work.