Difference between Constant and Readonly in C#

Constant

Readonly

Value is evaluated at compile time

Value is evaluated at runtime

Can be declared as class member or inside a method

Is not allowed inside a method

Is always static

Can be static or instanceable

Constant field can’t be used with static modifier

Readonly field can be used with static modifier

Can only be initialized at declaration

Can be initialized at declaration or in the constructor

Ebook Download
View all
Learn
View all