Friday, 8 July 2011

Difference between const and readonly in C#


'const':
  • Constants are static by default.
  • Could be declared within functions.
  • The value of your const property is set at compile time and can't change at runtime.
  • Const can't be anything except value (primitive) types.
  • Initiailized at declaration only.

'readonly':
  • Can be either instance-level or static.
  • Value is evaluated at run time.
  • Can be initialized in declaration or by code in the constructor.

No comments:

Post a Comment