This is true. Declaring a variable const has that implication.
In fact, every reference made to a "const" variable, will be replaced with
the value of the variable when the code is compiled. Not just method calls.
This has some reprecussions when other people depend on your code. Take the
following scenario. Company A's product depends on your dll which contains
constant definitions. They ship their product built against version 1 of
your dll. Then you ship version 2 of the dll in which some of the
constants' values have changed. Because Company A's product was compiled
against version 1 of your dll, they are still using the constant values from
version 1. This could potentially cause their app to break.
--
Jared Parsons [MSFT]
ja******@online.microsoft.com
This posting is provided "AS IS" with no warranties, and confers no rights.
OR if you wish to include a script sample in your post please add "Use of
included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm"
"J.Marsch" <je****@ctcdeveloper.com> wrote in message
news:um**************@TK2MSFTNGP11.phx.gbl...
Beware, though: I've read elsewhere that if you define a constant (as in
a const), and then use that constant as a parameter to a method call, that
the constant value (rather than a reference to the constant) will be encoded
method call. That's no big deal if you build all of your code at once,
but if the constant is in a shared shared, and you change its value in the
future, it won't necessarily "take" for existing, possibly deployed,
assemblies that use the constant value in a method call.
"Simon Harvey" <si**********@the-web-works.co.uk> wrote in message
news:uK*************@TK2MSFTNGP11.phx.gbl... Hi,
Is there any benefit to declaring variables as constants other than not
being able to overwrite them by mistake?
Thanks
Simon