Information Technology Reference
In-Depth Information
This code produces the following output:
Option settings:
Use Single Deck - True
Use Large Pictures - False
Use Fancy Numbers - True
Show Animation - True
More About Enums
Enums only have a single member type: the declared member constants.
￿
There are no modifiers that can be used with the members. They all implicitly have the
same accessibility as the enum.
￿
Since the members are constants, they are accessible even if there are no variables of the
enum type. Use the enum type name, followed by a dot and the member name.
For example, the following code does not create any variables of the enum type
TrafficLight , but the members are accessible, and can be printed out using WriteLine .
static void Main()
{
Console.WriteLine("{0}", TrafficLight.Green);
Console.WriteLine("{0}", TrafficLight.Yellow);
Console.WriteLine("{0}", TrafficLight.Red);
}
Enum name Member name
An enum is a distinct type. Comparing enum members of different enum types results in a
compile-time error. For example, the following code declares two enum types.
￿The irst if statement is fine because it compares different members from the same
enum type.
￿The second if statement produces an error because it compares members from differ-
ent enum types.
Search WWH ::




Custom Search