Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# simple switch

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

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

Thanks!

like image 595
Tom Gullen Avatar asked Sep 29 '26 02:09

Tom Gullen


2 Answers

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.

like image 118
Codesleuth Avatar answered Sep 30 '26 17:09

Codesleuth


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

like image 28
Ryan Berger Avatar answered Sep 30 '26 17:09

Ryan Berger