c# const vs readonly



c# const vs readonly

readonly keyword is used to define a variable 

which can be assigned once after the declaration 

either during declaration or in the constructor. 

  

const keyword is used to define a constant to be used in the program.


A const is a compile-time constant whereas readonly allows a value to be calculated at run-time and set in the constructor or field initializer. So, a 'const' is always constant but 'readonly' is read-only once it is assigned.


0 Comment's

Comment Form

Submit Comment