Monday, 13 April 2015

Difference Between Constant and ReadOnly and Static

Constant

Constant fields or local variables must be assigned a value at the time of declaration and after that they cannot be modified. By default constant are static, hence you cannot define a constant type as static.

ReadOnly

A readonly field can be initialized either at the time of declaration or with in the constructor of same class. Therefore, readonly fields can be used for run-time constants.

Static

The static keyword is used to specify a static member, which means static members are common to all the objects and they do not tied to a specific object.

No comments: