Axel Dahmen <NO*****@NoOneKnows.invalid> wrote:
can someone please enlighten me on the difference between a "const" and a
"readonly" declaration?
If a field is "const", anything which refers to the field has the value
of the constant placed into the IL - there is no runtime reference to
it. This has one potentially nasty side-effect - if you change the
value of a const field in one assembly (at compile-time, I mean) then
any other assemblies which need to see the "new" value need to be
recompiled - they won't try to "get" the value from the originating
assembly at runtime.
Consts are probably more performant (although it's unlikely to be
significant), but can only be applied to a limited range of types.
Of course, consts are also limited to those values which are known at
compile-time.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too