Returning multiple values from a function

crimaniak via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Sep 4 03:53:03 PDT 2017


On Monday, 4 September 2017 at 09:22:25 UTC, Vino.B wrote:

>  Thank you very much, i have used your idea and was able to 
> resolve, and i need one more favor. the below code outputs the 
> value but i need the name of the variable + value as below.
>
> Output :
> 1
> 2
> ["C:\\Temp\\TEAM1\\BACKUP", "C:\\Temp\\TEAM2\\ARCHIVE"]
>
> Required Output:
> Test1 = 1
> Test2 = 2
> Path = ["C:\\Temp\\TEAM1\\BACKUP", "C:\\Temp\\TEAM2\\ARCHIVE"]

For fixed names case you can hardcode it:
writeln("Test1 = ", Params[0]);
writeln("Test2 = ", Params[1]);
writeln("Path = ",  Params[2]);

You can't print the actual name of the variable used in tuple 
constructing because tuple doesn't store it. More of this, the 
tuple can be constructed from expression without a name, so it's 
impossible in common case.


More information about the Digitalmars-d-learn mailing list