Case Expressions

From The Oxygene Language Wiki

Jump to:navigation, search

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


Case expressions is a feature introduced in the May 2010 release.

It makes it possible to use case in an expression instead of a standalone statement. Instead of statements, case requires a (single) expression for each element and its else:

method ConsoleApp.ValuesText(aValue: Integer): string;
begin
  result := 'text: ' + case aValue of
      0: 'none';
      1: 'one';
      2: 'two';
      3..5 : 'several';
    else
      'many';
    end;


If the else case is omitted from the case, it defaults to nil (nullable type for value types, else reference type).

The result type of a case expression is the closest type that fits all members. For integers and doubles, it picks the type that can hold all values used (int + double -> double; int + int64 -> int64).


See Also


Oxygene-48.png

Area: Oxygene Language
Compiler version: Oxygene 5

Language GlossaryKeywordsTypesFAQHow To

Navigation
Areas
More
Toolbox