string-int[] array

Baz via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Mar 8 11:18:14 PDT 2015


On Sunday, 8 March 2015 at 18:05:33 UTC, Dennis Ritchie wrote:
> Is it possible to create such an array in which you can store 
> strings and numbers at the same time?
>
> string-int[] array = [4, "five"];

using an array of tuple it works:

----
import std.stdio;
import std.typecons;

alias T = Tuple!(string, int);

void main(string[] args)
{
     T[] tarr;
     tarr ~= T("a",65);
     tarr ~= T("b",66);
     writeln(tarr);
}
----

> [Tuple!(string, int)("a", 65), Tuple!(string, int)("b", 66)]


More information about the Digitalmars-d-learn mailing list