R.A.M. wrote:
When to use "readonly" and when to use "const"?
Could you explain me please?
Thank you very much!
'const' is evaluated at compile time, while 'readonly' -- at runtime.
The former is more efficient, but may have implications. If you
have an assembly which declares some public 'const' members and another
assembly which references it and uses that members, the second assembly
will have that values 'imprinted'. Which means that if you ever need
to change the value in the referenced assembly, you will need
to recompile and redistribute the referencing assembly too.
One more difference is that 'const' is also 'static' by definition.
Also, if your variable is not of primitive type (numeric or string)
you have no choice, only 'readonly' can be used.
I would say, in more cases than not 'readonly' is a better choice
since it guarantees correctness.