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

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

    As per this link, IF vs Switch comparison of iteration test using switch and if statement, is like for 1,000,000,000 iterations, Time taken by Switch Statement=43.0s & by If Statement = 48.0s

    Which is literally 20833333 iterations per second, So, Should we really need to focus more,

    P.S:Just to know the performance difference for small list of conditions.

提交回复
热议问题