Below are some differences:
Const
a. const member field must be initialized at the time of declaration.
b. const field can have only one value which is defined at the time of declaration.
c. const can't be static.
Readonly
a. readonly field can be initialized at the time of declaration or in the class's consructor.
b. The value of the readonly field once set at the time of declaration, can be updated at runtime.
c. readonly can be either instance-level or static.
Look at a const field to be a compile-time constant and readonly field as a runtime constant.
Difference between a Const and Readonly
Posted by Techie Cocktail | 12:28 AM | C-Sharp | 1 comments »
Subscribe to:
Post Comments (Atom)
short and to the point. i like it.