1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;
namespace OPeratorOvlApplication { class Box { private double length; private double breadth; private double height; public double getVolume() { return length * breadth * height;
} public void setLength(double len) { length = len; } public void setBreadth(double bre) { breadth = bre;
} public void setHeigth(double hei) { height = hei; } public static Box operator+(Box b,Box c) { Box box = new Box(); box.length = b.length + c.length; box.height = b.height + c.height; box.breadth = b.breadth + c.breadth; return box; } } class Program { static void Main(string[] args) { Box Box1 = new Box(); Box1.setLength(6.0); Box1.setBreadth(7.0); Box1.setHeigth(5.0);
Box Box2 = new Box(); Box2.setLength(12.0); Box2.setBreadth(13.0); Box2.setHeigth(10.0);
double volume = Box1.getVolume(); Console.WriteLine("Box1体积:{0}",volume); volume = Box2.getVolume(); Console.WriteLine("Box2体积:{0}", volume);
Box Box3 = new Box(); Box3 = Box1 + Box2; volume = Box3.getVolume(); Console.WriteLine("Box3体积:{0}", volume); Console.ReadKey();
} } }
|