Using the ternary operator for multiple operations

后端 未结 5 1830
萌比男神i
萌比男神i 2020-12-30 02:44

How can I use the ternary ? : condition to perform multiple operations, if expression is true/false?

wbsource = (exp) ? (Do one thing) : (Do secon

5条回答
  •  天命终不由人
    2020-12-30 03:32

    If you really, really want to, you could use a function which has side effects:

    filename = (fp!=null) ? DoOneThing(...) : DoAnotherThing(...);
    

    Though whoever maintains your code won't thank you.

提交回复
热议问题