
daniel benisti
11,362 Pointswhy is there an error
what is wrong in my code?
int value = -1;
string textColor = null;
(value < 0) ? textColor = "red" : textColor = "green";
1 Answer

Steven Parker
177,844 PointsThe ternary operator creates an expression, it's not a control statement. So instead of embedding assignments within it, assign the result of the entire expression to the variable:
textColor = (value < 0) ? "red" : "green";