Ternary operators in C#

Posted by pm_2 on Stack Overflow See other posts from Stack Overflow or by pm_2
Published on 2010-05-04T12:51:02Z Indexed on 2010/05/04 12:58 UTC
Read the original article Hit count: 139

Filed under:
|
|
|

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();

However, is there any way to do the same thing, without returning a value? For example, something like (assuming Func1() and Func2() return void):

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

I realise this could be accomplished using an if statement, I just wondered if there was a way to do it like this.

© Stack Overflow or respective owner

Related posts about c#

Related posts about methods