1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Switch statement

Discussion in 'C#' started by roe1512000, Sep 9, 2010.

  1. roe1512000

    roe1512000 New Member

    Joined:
    Sep 9, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hello everyone,

    I am experimenting with the switch statement and I can't get it to work.

    For example,

    If I choose "Yes" it will also print the ConsoleWriteLine's for "No" and "Maybe". How can I get it to not do that? i am using VS2005.

    Code:
    foreach (string s in responses)
                {
                    switch (s)
                    {
                        case "Yes":                                                     
                                               
                        Console.WriteLine("I am good also");
                        break;                   
                        
                        case "No":
                            Console.WriteLine("thats to bad");
                            break;
    
                        case "Maybe":
                            Console.WriteLine("???");
                            break;
    
                        default:
                            Console.WriteLine("???");
                            break;
    
                      }
                }
     

Share This Page