first_page the funky knowledge base
personal notes from way, _way_ back and maybe today

C#: the differences between readonly and const; MSDN; l-value

The readonly keyword is different from the const keyword. A const field can only be initialized at the declaration of the field. A readonly field can be initialized either at the declaration or in a constructor. Therefore, readonly fields can have different values depending on the constructor used. Also, while a const field is a compile-time constant, the readonly field can be used for runtime constants…

[http://msdn.microsoft.com/en-us/library/acdd6hb7(VS.71).aspx]

Attempting to assign a value to a readonly member will cause the compiler error, “The left-hand side of an assignment must be an l-value.”

Some languages use the idea of lvalues and rvalues. Lvalues are values that have addresses, meaning they are variables or dereferenced references to a certain memory location. Rvalues are non-lvalues—a term only used to distinguish from lvalues. In C, the term lvalue originally meant something that could be assigned to (coming from left-value, indicating it was on the left side of the assignment operator), but since ‘const’ was added to the language, this now is termed a ‘modifiable lvalue’.

The lvalue expression designates (refers to) an object. A non-modifiable lvalue is addressable, but not assignable. A modifiable lvalue allows the designated object to be changed as well as examined. An rvalue is any expression that is not an lvalue. It refers to a data value which is “immediate value” (look below) and consequently not addressable.

The notion of lvalues and rvalues was introduced by CPL. [Combined Programming Language]

[http://en.wikipedia.org/wiki/Value_(computer_science)]

mod date: 2009-08-13T03:23:09.000Z