Coalesce (Compiler Magic Function)

From The Oxygene Language Wiki

Jump to:navigation, search

This is a Language topic
Feel free to add your notes to this topic below.


The coalesce returns the first non-nil or assigned nullable value in its parameters, or the last parameter if none of them is assigned. It supports both reference and nullable value types, a value type can be used as the last value in the parameter list, which will be returned when the values before are nil.

The result type is a type all expressions have in common, or System.Object. If nullable types are used, the result type will be nullable, unless the last parameter is a value type of the same type as the nullable, in which case it will return that type.

method coalesce(expr1, expr2[, expr3 ...]): value

Example

Consider the following code:

var n1, n2: nullable Integer;
var s: string;

var r1 := coalesce(n1, n2);    // nullable integer
var r2 := coalesce(n1, 15);    // integer
var r3 := coalesce(n1, s);     // System.Object
var r4 := coalesce(s, 'test'); // string


See Also


Oxygene-48.png

Area: Oxygene Language
Compiler version: Oxygene 5

Language GlossaryKeywordsTypesFAQHow To

Navigation
Areas
More
Toolbox