Enum conversion

Steven Schveighoffer schveiguy at gmail.com
Wed Apr 22 12:00:17 UTC 2020


On 4/22/20 6:36 AM, Russel Winder wrote:
> Though for converting a ulong to a ubyte, I am assuming to!ubyte(x) is
> the right tool for the job.

It depends! If you know that the long will fit in a ubyte, by all means 
just use a cast. It's the fastest option. If you have no idea the value 
of the long, but it's *supposed* to fit into a ubyte, use to if you want 
an exception for those outside the range. And if you don't care, and 
just want a ubyte, use a cast.

But the compiler isn't going to accept ubyte(someLong).

-Steve


More information about the Digitalmars-d-learn mailing list