The switch Decision Statement - Day 1 - Part 13

Sign in to queue

Description

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

Embed

Download

Download this episode

The Discussion

  • User profile image
    Nique26

    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
    Clint

    @Nique26: the correct solution would be to replace

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

    with

    myTextBlock.Text = message;

  • User profile image
    petaganayr

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

    to

    message = "new car";

  • User profile image
    mmio

    hi

  • User profile image
    el_alien

    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.