Switch and
if else are fundamentally different but both might replace each other in some cases. Switch evaluates a single expression and base on different results of the expression it selects different cases.
switch (i)
{
case 1:
Console.Write("1");
break;
case 2:
Console.Write("2");
break;
default:
Console.Write("default");
break;
}
However, In case of if else, it eveluates multiple boolean expression and base of true or false , takes action
if(i>40)
{
do something
}
else if(i>25 && i<35)
{
do something
}
else if(i<20)
{
do something
}