July 31, 2015

Constant Vs Readonly in Asp.Net

Difference between Const and Read only in Asp.Net

You set a value to const member whose value will not change during execution of program
You set a value to read only  member whose value will change in constructor only
You can not change a value once assigned
Only in constructor
Set at compilation time
Set during run time

Constant variables are declared and initialized at compile time. The value can’t be changed after wards. Read-only variables will be initialized only from the Static constructor of the class. Read only is used only when we want to assign the value at run time.