Search........

Google

Friday, March 7, 2008

switch statements

/*Now let us see the multiple selection statements ,for these pourpose we can use switch statements

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;

}

}

}

}

No comments: