In C#, I am trying to shorten some of my return code. What I want to do is something like
condition ? return here:return there;
or
condition ?? return here;
I am having some issues though, the compiler says the expression is not valid. Here is an example:
int i = 1;
int a = 2;
i < a ? i++ : a++;
This is not valid. However,
int i = 1;
int a = 2;
int s = i < a ? i++ : a++;
is valid. Must there be assignment to use this shorthand notation? The only way I can think of using this at the moment is:
int acceptReturn = boolCondition ? return toThisPlace() : 0 ;
I would really like that line of code to look more like:
boolCondition ? return toThisPlace():;
Which is not valid but is what I am after.