const variables cannot be changed during compilation time. They are good for things that are really persistent (i.e. pi)
static members are shared memory that is accessible to all instances of a particular class and more if access modifiers are used, as a public (they can feel like global variables in programming languages โโlike JavaScript). Static members behave like regular variables that can be reassigned each time.
In your case, if the numbers are guaranteed never to change, then make them const. If they change, you will have to recompile the program with the new value.
Which one is better? if you use const , then literal values โโbecome baked in the assembly and provide improved performance.
If the values โโever need to be changed, then the time taken to change the source and recompile quickly destroys this marginal increase in performance.
source share