syntax :- switch(expression)
{
case value1:
body;
break;
case value2:
body;
break;
case value3:
body;
break;
default :
body;
break; //executes if all other conditions are wrong....
*/
using System;
namespace switchdemo
{
class class1
{
static void Main()
{
char ch;
Console.WriteLine("enter your choice (a,b,c,d)");
ch=Convert.ToChar(Console.ReadLine());
switch(ch)
{
case 'a' :
Console.WriteLine("This is from case a");
break;
case 'b' :
Console.WriteLine("This is from case b");
break;
case 'c' :
Console.WriteLine("This is from case c")
;
break;
case 'd' :
Console.WriteLine("This is from case d");
break;
default :
Console.WriteLine("This not from the specified choice");
break;
}
}
}
}
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfQak37-72ejQcVHg5EbuxzAAlQfqvbp4EIAZmn2j9eGfdsWialXWyPwzE4xdewcJ_bp8P2dEx03yeBEugCiBw0YrtmpjaPiSpIK5Oo1VFt2tyYSNNAfJvKBpMl-WVR5w_15g-UftpInTP/s320/switch.bmp)
No comments:
Post a Comment