Conversions

   


Only explicit conversions are possible for converting to (from) any integer type (not char, though) from (to) an enum type by using the cast operator (<Type>). However, the number 0 (zero) is an exception. It can be implicitly converted to an enumerator type; the reason is displayed in the Tip box.

It is also possible to explicitly convert one enumerator type to another enumerator type.

Tip

graphics/bulb.gif

The only numeric value that can be implicitly converted to an enumerator type is 0.

To reset or initialize an enumeration variable is the equivalent of assigning it the first member of the enumeration. If the first member of any enumeration is always set to have the value 0, it's possible to utilize the value 0 when initializing an enumeration. For example to initialize currentDay, we can simply write

 currentDay = 0; 

Therefore, always define one of the members of the enumeration to represent the value 0.



   


C# Primer Plus
C Primer Plus (5th Edition)
ISBN: 0672326965
EAN: 2147483647
Year: 2000
Pages: 286
Authors: Stephen Prata

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net