c# - Why is this failing to compile? -


i have requirement execute expression contains math , conditional statements , switch statement. i've tried this:

20 + 10 + (if (20 > 10){ return 0.2; } else { return 0.1; }) //+ switch case 

now compiler throws compilation errors expression. why, , how can fix work?

you're looking '?' operator inline 'if/else'.

as inline switch statement, suggest using static dictionary instead;

so line

20 + 10 +(if(20>10){ return 0.2} else{ 0.1 }) + switch case 

becomes

20 + 10 + (20 > 10 ? 0.2 : 0.1) + _switchdictionary[switchkey] 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -