Is there any significant difference between using if/else and switch-case in C#?

前端 未结 20 1238
时光取名叫无心
时光取名叫无心 2020-11-22 07:25

What is the benefit/downside to using a switch statement vs. an if/else in C#. I can\'t imagine there being that big of a difference, other than m

20条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-22 07:34

    often it will look better - ie will be easier to understand what's going on. Considering the performance benefit will be extremely minimal at best, the view of the code is the most important difference.

    So, if the if/else looks better, use it, otherwise use a switch statement.

提交回复
热议问题