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

前端 未结 20 1107
时光取名叫无心
时光取名叫无心 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:31

    The compiler is going to optimize pretty much everything into the same code with minor differences (Knuth, anyone?).

    The difference is that a switch statement is cleaner than fifteen if else statements strung together.

    Friends don't let friends stack if-else statements.

提交回复
热议问题