1

Possible Duplicate:
C#: Static readonly vs const

Which is preferable in this instance (no pun intended): "const" or "static readonly"?

I changed some const declarations to static readonly after either reading that was better or being adivsed somewhere (quite possibly here on StackOverflow).

Now ReSharper wants to change:

private static readonly int NUMBER_OF_QUARTER_HOURS = 96;

to:

private const int NUMBER_OF_QUARTER_HOURS = 96;

Should I submit or "draw iron"?

Community
  • 1
  • 1
B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862
  • 2
    This question is asked every second day on SO. – Tim Schmelter Jun 07 '12 at 21:56
  • 3
    Have you noticed that the naming conventions for .NET are **NumberOfQuarterHours** for static and const fields? (PascalCase and not ALL_CAPS.) – Danny Varod Jun 07 '12 at 21:56
  • 3
    @Danny - Yes, I have seen that before, but I don't like it, as it's then not clear (to me, anyway) that it's a const. – B. Clay Shannon-B. Crow Raven Jun 07 '12 at 22:01
  • How does the consumer of a constant care whether it is constant or not? – Tergiver Jun 07 '12 at 22:03
  • @ClayShannon Does it really matter if it is a const!? What matters is that the values is correct (unless you are trying to pass it as a parameter to an attribute). Anyway, the IDE gives great indications in the auto complete dialog and on mouse over. Uniform standards gives a great advantage and .NET has a pretty good standard. – Danny Varod Jun 07 '12 at 22:04

1 Answers1

0

const if you know the value before compile time.

Myles McDonnell
  • 12,943
  • 17
  • 66
  • 116
  • That is not necessarily true; the link @Tim posted shows an example where a compile-time value should be `static readonly`. – Dour High Arch Jun 07 '12 at 21:59