Beispiel #1
0
        static void DemoOperatorOverloading()
        {
            Cylinder barrel = new Cylinder(5, 20);
            Console.WriteLine("The volume is " + barrel.Volume);

            Cylinder doubleBarrel = barrel + barrel;
            Console.WriteLine("The volume is " + doubleBarrel.Volume);
        }
Beispiel #2
0
 // TODO: Add Operator to combine Cylinders
 public static Cylinder operator +(Cylinder leftSide, Cylinder rightSide)
 {
     Cylinder result = new Cylinder(leftSide.Radius, leftSide.Height + rightSide.Height);
     return result;
 }