public Vector Addition(Vector v) { return new Vector() { X = this.X + v.X, Y = this.Y + v.Y }; }
static void Main(string[] args) { Vector A = new Vector(1, 2); Vector B = new Vector(2, 4); Vector C = A.Addition(B); Console.WriteLine("C : {0}", C); Vector D = A + B + C; Console.WriteLine("D : {0}", D); Vector E = A + 10; Console.WriteLine("E : {0}", E); A += 10; Console.WriteLine("A : {0}", A); Console.WriteLine("A == E : {0}", A == E); Console.WriteLine("A != E : {0}", A != E); Console.WriteLine("A.Equals(E) : {0}", A.Equals(E)); Console.WriteLine("A.Equals(new object()) : {0}", A.Equals(new object())); Console.ReadLine(); }
static void Main(string[] args) { Vector v1 = new Vector(1, 2, 3); Vector v2 = new Vector(4, 5, 6); Console.WriteLine("The sum of {0} and {1} is {2}.", v1, v2, v1 + v2); }