Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (7.13 KB, 1 trang )
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
{