Is there a shorthand for the ternary operator in C#? -


background

in php there shorthand ternary operator:

$value = ""; echo $value ?: "value empty"; // same $value == "" ? "value empty" : $value; 

in js there's equivalent:

var value = ""; var ret = value || "value empty"; // same var ret = value == "" ? "value empty" : value; 

but in c#, there's (as far know) "full" version works:

string value = ""; string result = value == string.empty ? "value empty" : value; 

so question is: there shorthand ternary operator in c#, , if not, there workaround?

research

i found following questions, they're referring use ternary operator shorthand if-else:

shorthand if statements: c#

benefits of using conditional ?: (ternary) operator

and one, it's concerning java:

is there php short version of ternary operator in java?

what have tried

use shorthand style of php (failed due syntax error)

string value = ""; string result = value ?: "value empty"; 

use shorthand style of js (failed because "the || operator not applicable string , string.")

string value = ""; string result = value || "value empty"; 

there no shorthand when string empty. there shorthand when string null :

string value = null; string result = value ?? "value null"; 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -