forked from rstropek/Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
53 lines (44 loc) · 1.16 KB
/
Copy pathProgram.cs
File metadata and controls
53 lines (44 loc) · 1.16 KB
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
var v = new Vector3DNew(1, 2, 3);
v += new Vector3DNew(4, 5, 6);
Console.WriteLine(v);
var vTraditional = new Vector3D(1, 2, 3);
vTraditional += new Vector3D(4, 5, 6);
Console.WriteLine(vTraditional);
class Vector3D
{
public double X { get; set; }
public double Y { get; set; }
public double Z { get; set; }
public Vector3D(double x, double y, double z)
{
Console.WriteLine("Allocating a vector (traditional)");
X = x;
Y = y;
Z = z;
}
public static Vector3D operator +(Vector3D left, Vector3D right)
{
return new Vector3D(left.X + right.X, left.Y + right.Y, left.Z + right.Z);
}
public override string ToString() => $"({X}, {Y}, {Z})";
}
class Vector3DNew
{
public double X { get; set; }
public double Y { get; set; }
public double Z { get; set; }
public Vector3DNew(double x, double y, double z)
{
Console.WriteLine("Allocating a vector");
X = x;
Y = y;
Z = z;
}
public void operator +=(Vector3DNew v)
{
X += v.X;
Y += v.Y;
Z += v.Z;
}
public override string ToString() => $"({X}, {Y}, {Z})";
}