Ternary operators in C#

后端 未结 4 899
你的背包
你的背包 2020-12-16 18:30

With the ternary operator, it is possible to do something like the following (assuming Func1() and Func2() return an int:

int x = (x == y) ? Func1() : Func2(         


        
4条回答
  •  感情败类
    2020-12-16 19:03

    No, because the ternary operator is an expression, whereas actions/void functions are statements. You could make them return object, but I think that an if/else block would make the intent much clearer (i.e. the actions are being executed for their side-effects instead of their values).

提交回复
热议问题