adddesign

By Think Positive, Get Positive on 3:45:00 PM

Filed Under:

SWITCH statement

The switch expression must be of an integers, such as char, byte, short, ushort, int or any type of string. Thus the floating point expressiond are not allowed. The case constants must be literals of a type compatible with the expression. Two case constants in the came switch cannot have identical values. The default statement is executed if no case constants matches the expression. The default statement is optional..

Program Demonstrates the switch statement


using system;
class demoswitch
{
public static void Main()
{ int i;
for(i=0; i<6;i++)
switch(i)
{
case 0:
Console.WriteLine("i is zero");
break;
Case 1:
Console.WriteLine("i is one");
break;
Case 2:
Console. WriteLine("i is two");
break;
case 3:
Console.WriteLine("i is three");
break;
case 4:
Console.WriteLine("i is four");
break;
default:
Console.WriteLine("i is five or than more than five");
break;
}
}
}
class="para">output:

i is zero
i is one
i is two
i is three
i is four
i is five or more than five

0 comments for this post