2

Если я вызову метод Console.WriteLine("Hello!"); он будет оператором или выражением, или выражением он будет считаться тогда,когда метод будет возвращать некоторое значение?

3
  • Оператор это statement?
    – dIm0n
    6 сен 2020 в 11:36
  • @dIm0n да,но не уверен,что употребляю этот термин правильно
    – n_enrai49
    6 сен 2020 в 11:50
  • 3
    Expressions, Statements 6 сен 2020 в 12:03

1 ответ 1

4

Открываем спецификацию:

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

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.