int
, one for
double
,
and one for objects of type
ThreeD
. These are passed to the
ByTwos
constructor when
objects of their respective types are created. Pay special attention to
ThreeDPlusTwo( )
,
shown here:
// Define plus two for ThreeD.
static ThreeD ThreeDPlusTwo(ThreeD v) {
if(v==null) return new ThreeD(0, 0, 0);
else return new ThreeD(v.x + 2, v.y + 2, v.z + 2);
}
Notice that it first checks if
v
is
null
. If it is, then it returns a new
ThreeD
object in which
all fields are set to zero. The reason for this is that
v
is set to
default(T)
by the
ByTwos
constructor. This value is zero for value types and
null
for object types. Thus, (unless
SetStart( )
has been called) for the first increment,
Do'stlaringiz bilan baham: |