Apart from the apparent difference of
- having to declare the value at the time of a definition for a
const
VSreadonly
values can be computed dynamically but need to be assigned before the constructor exits.. after that it is frozen. - ‘const’s are implicitly
static
. You use aClassName.ConstantName
notation to access them.
There is a subtle difference. Consider a class defined in AssemblyA
.
public class Const_V_Readonly
{
public const int I_CONST_VALUE = 2;
public readonly int I_RO_VALUE;
public Const_V_Readonly()
{
I_RO_VALUE = 3;
}
}
Advertisements
Leave a Reply