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
Post a Comment