The switch Decision Statement - Day 1 - Part 13

Download this episode

Download Video


Picking back up on the notion of adding logic to your code, we look at a second decision statement—the switch—and compare its usefulness to the “if” statement we previously looked at.

Download the source code in c#

Download the source code in VB.Net



Available formats for this video:

Actual format may change based on video formats available and browser capability.

    The Discussion

    • User profile image

      This might not be HUGELY important but your code has an error (in the video and the download).  When you introduced the String.Format you should only have car, boat, cat or "... Sorry we didn't understand your response.  You lose" in your message statement.

      ** Easy fix for someone who is familiar with programming language but to a newbie they might get a wee bit lost.  As the output is not what is expected or originally intended by the programmer.

    • User profile image

      @Nique26: the correct solution would be to replace

      myTextBlock.Text = String.Format("You won a {0}!", message);


      myTextBlock.Text = message;

    • User profile image

      Or, just change message = "You won a new car!";


      message = "new car";

    • User profile image


    • User profile image

      Nope, the code on the video works, is the download that have some bug in it.

      If you copy paste the entire code on a new proyect (and name the textBlock and textBox just like the names on the video) the code works.

    Comments closed

    Comments have been closed since this content was published more than 30 days ago, but if you'd like to send us feedback you can Contact Us.