Expression Versus Statement

前端 未结 21 2001
别那么骄傲
别那么骄傲 2020-11-22 11:54

I\'m asking with regards to c#, but I assume its the same in most other languages.

Does anyone have a good definition of expressions and statements

21条回答
  •  借酒劲吻你
    2020-11-22 12:27

    An expression is something that returns a value, whereas a statement does not.

    For examples:

    1 + 2 * 4 * foo.bar()     //Expression
    foo.voidFunc(1);          //Statement
    

    The Big Deal between the two is that you can chain expressions together, whereas statements cannot be chained.

提交回复
热议问题