Close

c# – Switch statements (aka case statements)

Here is a quick switch statement demo:

[csharp]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SwitchStatementDemo
{
class Program
{
static void Main(string[] args)
{
Console.Write("enter a number: ");
//the parse converts the input into an integer.
int input = int.Parse(Console.ReadLine());

switch (input)
{
case 1: // this is how to do an "or" in switches.
case 2:
Console.WriteLine("You picked 1 Or 2");
break;
case 3:
Console.WriteLine("You picked 3");
break;
case 4:
Console.WriteLine("You picked 4");
break;
default:
Console.WriteLine("You picked a non-matching number");
break;
}

Console.WriteLine("Switch statement has ended");
}
}
}

[/csharp]