Which one is better when performance is taken into consideration an if else if or switch case
Duplicate: Is there any significant difference between using if/else and switch-case in C#?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
For both readability and sense use a switch statement instead of loads of IF statements.
The switch statement is slightly faster though:
http://www.blackwasp.co.uk/SpeedTestIfElseSwitch.aspx (first hit on Google)
The compiler can optimise the switch statement so use that if you have more than, I would say, 3 or 4 different cases