How can i get the value from an enum when passed to a function?
Gary Willoughby
dev at nomad.so
Sun Jan 19 09:37:52 PST 2014
How can i get the value from an enum when passed to a function?
For example i have the following code:
import std.stdio;
enum E : string
{
one = "1",
two = "2",
}
void print(E e)
{
writefln("%s", e);
}
void main(string[] args)
{
print(E.one);
}
The output is 'one'. How can i get at the value '1' instead. I
could change the print function to accept a string like this:
void print(string e)
{
writefln("%s", e);
}
but i lose the constraint of using an enum for the values.
More information about the Digitalmars-d-learn
mailing list