Если я вызову метод Console.WriteLine("Hello!"); он будет оператором или выражением, или выражением он будет считаться тогда,когда метод будет возвращать некоторое значение?
1 ответ
Открываем спецификацию:
12.7.6 Invocation expressions
12.7.6.1 General
An invocation-expression is used to invoke a method.
invocation-expression:
primary-expression ( argument-list opt )
То есть вызов метода - это выражение. Вызов метода является выражением, даже если тип возвращаемого значения void, об этом сказано далее в том же пункте:
The result of evaluating an invocation-expression is classified as follows:
• If the invocation-expression invokes a method or delegate that returns void, the result is nothing. An expression that is classified as nothing is permitted only in the context of a statement-expression (§13.7) or as the body of a lambda-expression (§12.16). Otherwise a binding-time error occurs.
• Otherwise, the result is a value, with an associated type of the return type of the method or delegate