How to get value of enum without casting
tcak via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Jul 9 09:20:56 PDT 2015
[code]
const enum FieldLength: uint{
Title = 64
}
const string SQL1 = "title CHAR(" ~ std.conv.to!string(
FieldLength.Title ) ~ ")";
void main() {
writeln( FieldLength.Title );
writeln( SQL1 );
}
[/code]
Result is
---------------
Title
Char(Title)
I can do cast(uint)( FieldLength.Title ) to fix this, but then I
am repeating the type of `enum`.
Is there any way to get the type of enum without interacting with
its items?
Is there any way to get string representation of an item of enum
without casting?
More information about the Digitalmars-d-learn
mailing list