views:

114

answers:

3
+2  Q: 

c# simple switch

Feel like an idiot :) Why does this not work?

switch (sortCol)
{
case: "username"
    mnu_username.Text = "";
    break;
case default
    break;
}

Thanks!

+10  A: 
switch (sortCol)
{
    case "username":
        mnu_username.Text = "";
        break;
    default:
        break;
}

Have you not got an IDE to highlight syntax errors for you?
Also note that if sortCol is not a string, this won't work.

Codesleuth
Perfect thanks, yes it did highlight errors in VS2008 but they were not very helpful for switch statements
Tom Gullen
Ahh I see :) I've on some occasions reverted back to the Pascal case statements and scratched my head for a few moments until I realise I missed `switch`. Fridays...
Codesleuth
+5  A: 

case default should be changed to default:. Then your switch statement should work.

Ryan Berger
+1  A: 
switch (sortCol)
            {
                case "username":
                    mnu_username.Text = "<img src=\"../images/" + sortType + ".png\" class=\"adIco\" />";
                    break;
                default:
                    break;
            }
Tom Gullen