Find variable at run time

Josh moonburntm at gmail.com
Fri May 17 14:12:50 PDT 2013


Instead of doing this:

void main()
{
     int x, y, z;
     write("Increment which variable: ");
     string input = readln()[0..$ - 1];
     final switch (input)
     {
         case "x":
             x++;
             break;
         case "y":
             y++;
             break;
         case "z":
             z++;
             break;
     }
     writeln(x, y, z);
}

Is something like this possible in D?

void main()
{
     int x, y, z;
     write("Increment which variable: ");
     string input = readln()[0..$ - 1];
     findVar(input)++;
     writeln(x, y, z);
}

Thanks

Josh


More information about the Digitalmars-d-learn mailing list