The switch statement is a control statement that selects a switch section to execute from a list of candidates.
Each switch section contains one or more case labels and a list of one or more statements. The following example shows a simple switch statement that has three switch sections. In this tutorial we want to get result of garde in Labelbox.
Ingredients:
1) Two Label Boxes
2) One Textbox
3) One Button
Programming:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string grade;
string Value;
Value = textBox1.Text;
grade = Value;
switch (grade)
{
case "A":
label1.Text = ("Excellent Sarib!");
break;
case "B":
label1.Text = ("Good Sarib");
break;
default:
label1.Text =("Invalid grade");
break;
}
}
}
}
( Before )
( After )
No comments:
Post a Comment