M
My4thPersonality
I am reading something about the details of C#, and I came acros the
statements readonly and const. I do not understand, it seems to be the same,
what's the difference? Here is the text were it refers to:
const long size = ((long)int.MaxValue + 1) / 4;
Constant-Value must be computable at compile time
readonly DateTime date;
Read Only Field-Must be initialized in their declaration or in a
constructor-Value needs not be computable at compile time-Consumes a memory
location (like a field)
(Or it should be the latter, that const is created on the stack and readonly
on the heap??)
statements readonly and const. I do not understand, it seems to be the same,
what's the difference? Here is the text were it refers to:
const long size = ((long)int.MaxValue + 1) / 4;
Constant-Value must be computable at compile time
readonly DateTime date;
Read Only Field-Must be initialized in their declaration or in a
constructor-Value needs not be computable at compile time-Consumes a memory
location (like a field)
(Or it should be the latter, that const is created on the stack and readonly
on the heap??)