37
1
using System;
2
3
public class Box
4
{
5
public int Height { get; set; }
6
public int Width { get; set; }
7
8
public Box(int h, int w)
9
{
10
Height = h;
11
Width = w;
12
}
13
14
public static Box operator +(Box box1, Box box2)
15
{
16
int h = box1.Height + box2.Height;
17
int w = box1.Width + box2.Width;
18
Box result = new Box(h, w);
19
return result;
20
}
21
}
22
23
public class Program
24
{
25
public static void Main()
26
{
27
Box b1 = new Box(14, 3);
28
Box b2 = new Box(5, 7);
29
Box b3 = b1 + b2;
30
Box b4 = b1 + b2 + b3;
31
32
Console.WriteLine("Box b1: Height: {0}, Width: {1}", b1.Height, b1.Width);
33
Console.WriteLine("Box b2: Height: {0}, Width: {1}", b2.Height, b2.Width);
34
Console.WriteLine("Box b3: Height: {0}, Width: {1}", b3.Height, b3.Width);
35
Console.WriteLine("Box b4: Height: {0}, Width: {1}", b4.Height, b4.Width);
36
}
37
}
Cached Result
dest.A: 1