Created
October 8, 2019 04:57
-
-
Save peterthorsteinson/ccc9048114adf6022cf190ef9679e86a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Vector2D v1 = new Vector2D(3, 4); | |
Console.WriteLine(v1); | |
Vector2D v2; | |
v2.x = 5; | |
v2.y = 6; | |
Console.WriteLine(v2); | |
Vector2D v3 = v1 + v2; | |
Console.WriteLine(v3); | |
} | |
} | |
struct Vector2D | |
{ | |
public Vector2D(double x, double y) | |
{ | |
this.x = x; | |
this.y = y; | |
} | |
public double x; | |
public double y; | |
public static Vector2D operator +(Vector2D lhs, Vector2D rhs) // vector addition | |
{ | |
return new Vector2D(lhs.x + rhs.x, lhs.y + rhs.y); | |
} | |
public override String ToString() | |
{ | |
return $"x: {x}, y: {y}"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment