search

Google
 

Thursday, January 31, 2008

Difference between ReadOnly and Constants

Difference between ReadOnly and Constants

-> A constant is initialized at the time of its creation i.e Compile Time.

-> A ReadOnly can be assigned once in the class constructor allowing you to pass the value at Runtime.


Advantages of declaring Constant

->Declaring fields as constants protects from changing the value accidentally.

->Using constants we perform some optimization by not declaring any stack space for that field.


No comments: