Project Euler: Problem 1 (Possible refactorings and run time optimizations)

前端 未结 13 2050
半阙折子戏
半阙折子戏 2020-12-11 08:35

I have been hearing a lot about Project Euler so I thought I solve one of the problems in C#. The problem as stated on the website is as follows:

If w

13条回答
  •  情歌与酒
    2020-12-11 08:54

    The code in DivisibleByThreeOrFive would be slightly faster if you would state it as follows:

    return ((counter % 3 == 0) || (counter % 5 == 0));
    

    And if you do not want to rely on the compiler to inline the function call, you could do this yourself by putting this code into the Main routine.

提交回复
热议问题