Enum conversion

Russel Winder russel at winder.org.uk
Tue Apr 21 16:03:20 UTC 2020


Hi,

Given an enum:

enum ZoneNumber {
    One = 1,
    Two = 2,
}

then which of these is the right way of accessing the value?

cast(ubyte)ZoneNumber.One
to!ubyte(ZoneNumber.One)

conversely what is the right way of going the other way:

cast(ZoneNumber)1
to!ZoneNumber(1)

I tried:

enum ZoneNumber : ubyte {
    One = 1,
    Two = 2,
}

but the members One and Two still seem to be types as int. :-(


-- 
Russel.
===========================================
Dr Russel Winder      t: +44 20 7585 2200
41 Buckmaster Road    m: +44 7770 465 077
London SW11 1EN, UK   w: www.russel.org.uk

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20200421/86acac14/attachment.sig>


More information about the Digitalmars-d-learn mailing list