Thread: swich case

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Use "Direction.South" inistead of just "South".
    Yes there is fall-through, if by that you mean:
    Code:
    case 1:
    case 2:
    case 3:
      break;
    
    default:
      break;
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Quote Originally Posted by Magos View Post
    Use "Direction.South" inistead of just "South".
    Yes there is fall-through, if by that you mean:
    Code:
    case 1:
    case 2:
    case 3:
      break;
    
    default:
      break;
    One important difference is that you cannot fall through in C#. You'll get compiler warnings if you try. You can goto other labels:
    Code:
    switch(someNumber)
    {
      case 1: goto case 2;
      case 2: goto case 3;
      case 3:
        MessageBox.Show("You chose: " + someNumber);
        break;
    
      default:
        MessageBox.Show("You did not choose 1, 2, or 3.");
        break;
    }
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 11
    Last Post: 08-25-2008, 12:01 PM
  2. case ' ':
    By jaylc185 in forum C Programming
    Replies: 5
    Last Post: 06-08-2005, 05:28 PM
  3. help with swich cases
    By digdug4life in forum C++ Programming
    Replies: 15
    Last Post: 02-15-2005, 08:17 PM
  4. Swich/Case Question
    By Xzyx987X in forum C Programming
    Replies: 4
    Last Post: 05-05-2004, 02:26 PM
  5. upper case to lower case problem
    By Jasonymk in forum C++ Programming
    Replies: 3
    Last Post: 04-27-2003, 05:35 AM