Advertisement
//C# switch example
using System;
class Switch
{
public static void Main()
{
int i=30;
switch(i)
{
case 10:
Console.WriteLine("value is 10");
break;
case 20:
Console.WriteLine("value is 20");
break;
case 30:
Console.WriteLine("value is 30");
break;
default:
Console.WriteLine("This is default");
break;
}
}
}
value is 30
Advertisement
//C# switch example
using System;
public class SwitchEx
{
public static void Main()
{
char i='A';
switch(i)
{
case 'B':
Console.WriteLine("char value is B");
break;
case 'E':
Console.WriteLine("char value is A");
break;
case 'D':
Console.WriteLine("char value is D");
break;
default:
Console.WriteLine("This is default");
break;
}
}
}
This is default
//C# switch example
using System;
public class Switch
{
public static void Main()
{
int i=2;
switch(i)
{
case 1:
Console.WriteLine("value is 1");
break;
case 2:
Console.WriteLine("value is 2");
break;
case 3:
Console.WriteLine("value is 3");
default:
Console.WriteLine("This is default");
}
}
}
SwitchEx.cs(21,2): error CS0163: Control cannot fall through from one case label ('case 3:') to anotherS
SwitchEx.cs(23,2): error CS8070: Control cannot fall out of switch from final case label ('default:')
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement