Coffeehouse Post

Single Post Permalink

View Thread: Select Case behavior
  • User profile image
    cbae

    One thing about the C# switch statement is that it allows you to have the same code execute for different cases by allowing the code to fall through cases that have no code contained therein:

                switch (x)
                {
                    case 0:
                        //do something 0
                        break;
                    case 1:
                        //fall through
                    case 2:
                        //fall through
                    case 4:
                        //do something 1, 2, or 4
                        break;
                    case 3:
                        // do something 3
                        break;
                    default:
                        // do something default
                        break;
                }

    I find this to be quite useful.