I like to use switch statement rather than using continuous if statement or atleast if I have to use more than 3 if statement. The syntax and example can be a good reference.

SYNTAX:


switch (variable)
 {
 case 1:
 Console.WriteLine("Case 1");
 break;
 case 2:
 Console.WriteLine("Case 2");
 break;
 default:
 Console.WriteLine("Default case");
 break;
 }

 

Example:


string strCityName = "Madras";

 switch (strCityName)
 {

 case "Madras":
 Response.Write(strCityName.ToString() + " : Capital of Tamil Nadu");
 break;

 case "Kolkatta":
 Response.Write(strCityName.ToString() + " : Capital of West Bengal");
 break;

 case "Mumbai":
 Response.Write(strCityName.ToString() + " : Capital of Maharashtra");
 break;

 default:
 Response.Write(strCityName.ToString() + " : City not in the list");
 break;

 }