Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the C# 5.0 await keyword listed as an operator rather than a modifier?

The MSDN library lists the await keyword as an operator. That seems strange to me - I'd have thought it was a modifier, like the async keyword.

Why is this an operator?

like image 521
Jon Galloway Avatar asked Jul 31 '12 01:07

Jon Galloway


2 Answers

async is a modifier for a declaration. Similar to public.

await is an operation that consumes an asynchronous operator and does something with it. Similar to return.

await isn't modifying what is placed after it, but instead specifying how that operation is handled. In contrast async doesn't actually modify anything, it merely marks that a particular method is in the style of async (it is the eventual await's that perform all of the changes to the methods structure from a syntatic standpoint).

like image 109
Guvante Avatar answered Oct 12 '22 06:10

Guvante


A modifier applies to a declaration. The private, static, out, ref, params, override keywords are examples of that. And async.

An operator applies to an expression and transforms the expression result. What you write on the right of await is called the "await expression". It is thus a unitary operator.

like image 40
Hans Passant Avatar answered Oct 12 '22 06:10

Hans Passant