-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Learning D
By :
This section shows how to define custom types using enum, union, struct, and class. The latter two will be the focus for most of the remainder of the chapter.
The anonymous enumeration in D declares a set of immutable values. A major difference from C is that it's possible to specify the underlying type. When no fields are explicitly assigned a value, the underlying type of an enum defaults to int. Note that user-defined type declarations in D do not require a semicolon at the end:
enum {top, bottom, left, right} // type is int
enum : ubyte {red, green, blue, alpha} // type is ubyteThe members of each will be initialized with sequential values starting at 0. In the second declaration, the underlying type is explicitly set to ubyte by appending a colon and the type name to the enum keyword. enum values aren't restricted to integrals, or even just the basic types. Any type that D supports, be it one of the derived data types or even a user-defined type...
Change the font size
Change margin width
Change background colour