This is simple C# switch example. Which takes integer parameter and based on input it prints the string values. If no match found it executes Default case.
You can also use string values in switch statements.
Output:
Source code of Switch Statement:
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Program obj = new Program();
obj.SwitchExample(2);
obj.SwitchExample(12);
Console.ReadLine();
}
private void SwitchExample(int temp)
{
switch (temp)
{
case 2:
Console.WriteLine("Number Two");
break;
case 3:
Console.WriteLine("Number three");
break;
default:
Console.WriteLine("Other Number");
break;
}
}
}
}
No comments:
Post a Comment