They seems to be functionally similar, and, beside acting as a reminder to myself that “const int” are meant to stay the same and I should avoid editing them, I can’t see any difference between. So I’m wondering, in what situations would I choose one over the other?
Apart from the fact you mentioned, the other main difference is that the compiler will turn your
const int Pizza = 10;
into
const static int Pizza = 10;
the reason is logic since you declare the value in the class to be constant, it will be for all instances and then can be made static.
The situation in which you want this is also simple, whenever you don’t want the value to change and you want to make sure it will not be allowed. It sounds useless because you know you don’t want to modify it but when working as team, you would have to put some warning around it or simply make it const. It is just a safety.
Using tools like ReSharper, the compiler would actually let you know that you are never modifying this value and you should make it a const (or readonly depending on where you initialize it).
I don’t have a great load of experience with c#, but if it’s anything at all like C++ (Which I can probably safely assume that it is) const is “Constant.” So, if you want your variable to be able to change, don’t make it constant. The great thing about constant though, is that the compiler catches it if you try to change it on accident. I suggest using it whenever possible, because it is a good habit to get into.