+ 3
Is there any method to simplify if else statement if the statement more than 2??
string name = ""; if(RadioButton1.Checked) { name = Orange; } else if(RadioButton2.Checked) { name = Apple; else { name = Peer; } Is there any method to simplify this code?
5 Respuestas
+ 6
If what you meant by "simplify" was less lines then you can try ternary operator, but IMHO that code stands better in readability level.
Ternary operator:
<condition> ? <true-block> : <false-block>
Equivalent to:
If <condition> evaluates to true execute <true-block> else execute <false-block>
You can nest this, but readability is rather poor. Choice is yours : )
+ 1
thank you
+ 1
I can suggest one more:
If(var)do this;
It's most simlify without "else" statsment.
Or
If(var)do this;
Else do this;
https://code.sololearn.com/c9pN2WesEEZI/?ref=app
0
You can get the name with event handler listener