title: Using the switch statement in a Windows Forms application
body: <p>And I'm doing some exercises about switch. I just did it from console application and I would like to do it in window forms applications. I'm looking for syntax on how to do switch in window forms. 
  In console it's usually like this:</p>
  
  <pre><code>switch (wordValue)
      {
       case 1:
       Console.WriteLine("You have entered numbered two");
       break;
       default:
       break;
  </code></pre>
  
  <p>how can I do this in my window forms, if I would like to display this cases in listbox1?</p>
  
  <p>Thanks</p>
  
  <p>=======</p>
  
  <p>Thank you. I tried this one but I'm getting an error. This is what I've tried:</p>
  
  <pre><code>     public static void WriteNumber(int wordValue)
      {
          switch (wordValue)
          {
              case 1:
                 listbox.Items.Add("You have entered number one");
                  break;
          }
      }
  </code></pre>
  
  <p>========</p>
  
  <p>This is the code I'm trying to do:</p>
  
  <pre><code>    private void btnOk_Click(object sender, EventArgs e)
      {
          string strUserInputNumber;
          strUserInputNumber = textBox1.Text.Trim();
          Int32 intNumber;
          if (Int32.TryParse(textBox1.Text, out intNumber))
          {
              listBox1.Items.Add(intNumber.ToString());
          }
      }
  
  
    public static void WriteNumber(int wordValue)
      {
          switch (wordValue)
          {
              case 1:
                 this.listBox1.Items.Add("You have entered numbered one");
                  break;
          }
       }
  </code></pre>
  
  <p>====</p>
  
  <p>This is the new code:</p>
  
  <pre><code>    private void btnOk_Click(object sender, EventArgs e)
      {
          string strUserInputNumber;
          strUserInputNumber = textBox1.Text.Trim();
          Int32 intNumber;
          if (Int32.TryParse(textBox1.Text, out intNumber))
          {
              listBox1.Items.Add(intNumber.ToString());
              WriteNumber(intNumber);
  
          }
          else
          {
             MessageBox.Show("Please enter an integer not a character");
          }
      }
  
      public void WriteNumber(int wordValue)
      {
          switch (wordValue)
          {
              case 1:
                  listBox2.Items.Add("You have entered numbered one");
                  break;
              case 2:
                  listBox2.Items.Add("You have entered numbered two");
                  break;
              case 3:
                  listBox2.Items.Add("You have entered numbered three");
                  break;
              default:
                  listBox2.Items.Add("You have exceeded the range of 1-3. Please enter the number between 1-3");
                  break;
          }
  </code></pre>