static void Main(string[] args) { MathVector mv1 = new MathVector(); MathVector mv2 = new MathVector(); mv1.AddRange(new decimal[] { 1, 3, 6}); mv2.AddRange(new decimal[] { -5, 3, 8 }); Console.WriteLine("mv1 + mv2 = {0}", mv1 * mv2); MathVector result = mv1 + mv2; Console.WriteLine("mv1 * mv2 = {0}", (mv1 + mv2).ToString()); Console.ReadKey(); }
public static MathVector operator +(MathVector vector1, MathVector vector2) { try { MathVector results = new MathVector(); for(int i = 0; i < vector1.Count; i++) { results.Add((decimal)vector1[i] + (decimal)vector2[i]); } return results; } catch(MathVectorDifferentLengthException ex) { Console.WriteLine("MathVectors must be the same length."); return null; } }