PART I
C h a p t e r 9 :
O p e r a t o r O v e r l o a d i n g
235
PART IPART I
if(a || c) Console.WriteLine("a || c is true.");
The
true
operator is first applied to
a
. Since
a
is true in this situation, there is no need to use
the
|
operator method. However, if the statement were rewritten like this:
if(c || a) Console.WriteLine("c || a is true.");
then the
true
operator would first be applied to
c
, which in this case is false. Thus, the
|
operator method would be invoked to determine if
a
was true (which it is in this case).
Although you might at first think that the technique used to enable the short-circuit
operators is a bit convoluted, it makes sense if you think about it a bit. By overloading
Do'stlaringiz bilan baham: |