Chapter 9 Quick Reference
To | Do this |
Declare an enumeration type | Write the keyword enum, followed by the name of the type, followed by a pair of braces containing a comma-separated list of the enumeration literal names. For example:
enum Season {Spring, Summer, Fall, Winter } |
Declare an enumeration variable | Write the name of the enumeration type on the left followed by the name of the variable, followed by a semicolon. For example:
Season currentSeason; |
Initialize or assign an enumeration variable to a value | Write the name of the enumeration literal name in combination with the name of the enumeration type it belongs to. For example:
currentSeason = Season; // compile time error currentSeason = Season.Spring; // okay |
Declare a struct type | Write the keyword struct, followed by the name of the struct type, followed by the body of the struct (the constructors, methods, and fields). For example:
struct Time { public Time(int hh, int mm, int ss) { ... } ... private int hours, minutes, seconds; } |
Declare a struct variable | Write the name of the struct type, followed by the name of the variable, followed by a semicolon. For example:
Time now; |
Initialize or assign a struct variable to a value | Initialize or assign the variable to a struct value created by calling a structure constructor. For example:
Time lunch = new Time(12, 30, 0); lunch = new Time(12, 30, 0); |