The assign statements – expressed as
:=, a colon followed by an equal sign – assigns the value of the expression on right to the writable expression on the left.
x := 5;
After the above statement,
x has a value of
Different from most other languages, Pascal and Oxygene purposely do not use the equal sign for assignment, to highlight the active nature of the statement – it is not expressing equality, but transferring a value (even if the end result – usually, but not always – is equality of the left and the right).
Writable expressions include:
- Local variables
- Field Access
- Property Access
resultof the current method
- Indexers for indexer properties or arrays
- Discardables (
- Tuple Literals
Note that in particular for Properties with custom setter code, and for Discardables, the end result of an assignment is not necessarily equality. For example, a property setter (or getter) code might modify the actual value.
Other uses of the
The assignment operator can also appear in other statements that are not stand-alone assign statements such as:
varDeclaration Statements with an initializer
- Field and Property declarations with an initializer
- Default Parameter values for Method declarations
- Property Initializers in
Notably, Consts use the
= operator to specify their value, and not
:=, since for constants, equality between the constant and the literal it is being initialized with is guaranteed, and a fundamental part of what makes them constants.