Overview

Complex Keys

Showcases the flexibility of associative arrays in DWScript. This example demonstrates using 'Integer' and 'Float' types as keys in addition to strings, highlighting the language's support for non-string indexing in dictionaries.

Source Code

var idMap: array [Integer] of String;

idMap[101] := 'Product A';
idMap[202] := 'Product B';
idMap[303] := 'Product C';

PrintLn('ID 202 belongs to: ' + idMap[202]);

// Using Float as keys (be careful with precision!)
var floatMap: array [Float] of String;
floatMap[3.14] := 'Pi';
floatMap[2.71] := 'Euler';

PrintLn('3.14 is ' + floatMap[3.14]);

// Checking length
PrintLn('ID Map Length: ' + IntToStr(idMap.Length));

Result

ID 202 belongs to: Product B
3.14 is Pi
ID Map Length: 3
On this page