Difference Between const and readonly

Medium2-4 Years

Both const and readonly are used to define immutable values.

const

  • Compile-time constant
  • Must be initialized during declaration

readonly

  • Runtime constant
  • Can be initialized in constructor

Example

const double PI = 3.14;

readonly int id;

Interview Tips

const is static by default.