how can i remove multiple if statement.?
eg. if (a=="something")
{
}else if(b==" something"
{
}
...
.....
like this if multiple of if condtion in program how can i remove it shortes one.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.


int result = Check() ? 1 : 0; switch (grade)
{ case 'A': Console.WriteLine("Excellent!"); break;
case 'B': Console.WriteLine("Good Job!"); break;
case 'C': Console.WriteLine("Well done"); break;
case 'D': Console.WriteLine("You passed"); break;
case 'F': Console.WriteLine("Better try again"); break;
default: Console.WriteLine("Invalid grade"); break; }




Jamil MoughalPosted Jul 8, 2017, 8:43 AM
Sivasankar GorantlaPosted Jul 6, 2017, 2:51 AM
Satyaprakash SamantarayPosted Jul 4, 2017, 12:20 AM
Vishal VermaPosted Jun 22, 2017, 1:27 AM
Simple way -Use switch case.
Advanced with few lines of code -Use any pattern suitable to your case .e.g -Strategy pattern
Anil JhaPosted Jun 22, 2017, 12:57 AM