DEV Community

Cover image for Const vs Readonly in C#
Sharad Aade
Sharad Aade

Posted on

Const vs Readonly in C#

const vs readonly

Const

  • ** Const is compiled time constant**
  • Declaration and initialization at the same time
  • Can not be changed public const int cmToMeter = 100;

Readonnly

  • Readonly is runtime constant
  • Decalaration and initialization not mandatory in same time we can intialise later on
  • We can change the value

public static readonly double PI = 3.1;
public static readonly double PI;
PI = 3.14

Top comments (0)