Fun with Tuples

One of the nice things about them is that they are strongly typed, even though accessed using a generic accessor. so for

var x: tuple of (String, Integer);

the compiler knows that x[0] is a String, and x[1] is an integer (and that x[2] doesn’t exist and is invalid)

1 Like

A single tuple is not as valuable as an array of them, in my case, initialized as global constants. Would the following be the correct way to do it?

const
MyNos : array[0…2] of tuple of (integer, string) =
[(0, ‘Zero’),
(1, ‘One’),
(2, ‘Two’)];

And then how to access individual elements:
MyNos[0, 1] = the string ‘Zero’ or
MyNos[0][1] = the string ‘Zero’?

I assume MyNos[1] is the tuple (1, ‘One’)?

I find them useful for method results.

Looks correct, yes.

Yes, this one. you cannot combine array and tuple access into a single indexer access expression, as this is not a multi-dim array.