Wednesday, June 20, 2007

Constant & Read Only




Read Only




Assign meaningful constant values as part of the initialization process.



Set at run time. But cannot be modified after the constructor has executed.



Can only be used for primitive types.

Run-time constants can be of any type


The IL generated for a compile-time constant contains the value, not the symbol. The value is already "burned in" at compile time.


The IL generated when you reference a readonly constant reference the readonly variable, not the value.



Class Level Scope

Capable of storing different values for each instance of a class type.




Ø  You can use const values as the parameters to attribute constructors; you cannot use readonly values, or variables.

So, when you define objects to use when constructing attributes, those values used for attribute parameters must be const; readonly doesn't work.




Thanks & Regards,

Arun Manglick

SMTS || Microsoft Technology Practice || Bridgestone - Tyre Link || Persistent Systems || 3023-6258


DISCLAIMER ========== This e-mail may contain privileged and confidential information which is the property of Persistent Systems Pvt. Ltd. It is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, you are not authorized to read, retain, copy, print, distribute or use this message. If you have received this communication in error, please notify the sender and delete all copies of this message. Persistent Systems Pvt. Ltd. does not accept any liability for virus infected mails.

No comments:

Post a Comment