Enumerator Operators

   


Listing 7.5 showed how to apply the operators assignment (=), equals (==), and increment (++) to enumerators. Numerous other operators can be used with enumerators; they are listed in Table 7.4.

Table 7.4. Operators Applicable to Enumerators
Binary +, -
Unary ++, --, ~
Comparison operators ==, !=, <, >, <=, >=
Logical &, |, ^
Assignment =, +=, -=
Primary sizeof

You have not met all of the symbols displayed in Table 7.4. The operators relevant to enumerators are included here for completeness and overview; they will be discussed in relation to enumerators in due time.

The binary operators + and - cannot be applied to two enumerator types. Instead, they are meant to combine one enumerator operand with one integer value operand, such as the following:

 currentDay = currentDay + 1; 

This statement is equivalent to

 currentDay++; 

The binary operators (+) and (-) do not look for the next enumerator in the list (just like the increment and decrement operators). They only add or subtract the integer value from the value the enumerator represents.


   


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

Similar book on Amazon

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