Yes, you're correct -- this can cause issues with versioning. Especially
when referenced from another module. Consider, since the constant is
embedded directly in the metadata, you no longer require the referenced
module *at all* -- changing the original value will have no effect until
all referencing modules and assemblies are re-compiled. On the other
hand, following Andera's earlier remark, readonly fields are referenced
at run-time, so changes in the original will immediately percolate to
the referring items.

John

> -----Original Message-----
> From: Moderated discussion of advanced .NET topics.
> [mailto:[EMAIL PROTECTED]] On Behalf Of
> Darren Neimke
> Sent: Thursday, July 04, 2002 6:31 AM
> To: [EMAIL PROTECTED]
> Subject: Re: [ADVANCED-DOTNET] Defining fixed variables
>
>
> Noam,
>
> When you use constants the compiler will embed (substitute)
> their values at compile time in the IL , so I presume that
> would be the equivalent.
> I.e.:
>
> const int THIS_VAL = 10 ;
> const int MAX_THAT = 255 ;
>
> Then, if you reference THIS_VAL or MAX_THAT in your code like so...
>
>     if( myValue >= MAX_THAT ) {}
>
> The compiler will embed the literal value at compile time, i.e.:
>
>     if( myValue >= 255 ) {}
>
> I think - but don't quote me - that the only tip-or-trick
> with this is that you have to watch what's happening in
> referencing assemblies when you make changes to the class
> that contains the const values.
>
>
> Cheers,
>
> Darren
>
> You can read messages from the Advanced DOTNET archive,
> unsubscribe from Advanced DOTNET, or subscribe to other
> DevelopMentor lists at http://discuss.develop.com.
>

You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced 
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to