Using the ternary operator for multiple operations

后端 未结 5 1828
萌比男神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:42

    Short answer, use an if block, its the only sane thing to do.

    Other answer, for the dirty, smelly insane individual.

    filename = (fp!=null) ? Func {fp = Properties.Settings.Default.filename; Properties.Settings.Default.Save; return fp;} : Properties.Settings.Default.file; 
    

提交回复
热议问题