When I want to use a colon “:” in my string switch case statement I get the error “unterminated string literal”, how can I fix this and why does it give the error?
Code:
@switch (stringText)
{
case "aaaa:ggg":
Do something...
break;
case "bbbb:ggg":
Do something else...
break;
}
If fixed it by doing this but don’t find it a good solution:
const string extra = ":ggg";
@switch (stringText)
{
case "aaaa" + extra:
Do something...
break;
case "bbbb" + extra:
Do something else...
break;
}
EDIT:MVC Razor syntax are used
How about if you define values as constants in a utility class and then refer to those constants instead of having string literals in the switch statement?
…