public static Fraction operator +(Fraction p1, Fraction p2) { Fraction result = new Fraction(); result.Numerator = p1.Numerator * p2.Denominator + p2.Numerator * p1.Denominator; result.Denominator = p1.Denominator * p2.Denominator; return result; }
static void Main(string[] args) { Fraction a = new Fraction(1, 2); Fraction b = new Fraction(1, 4); Fraction newFraction = a + b; Console.WriteLine("{0} + {1} = {2}", a.ToString(), b.ToString(), newFraction.ToString()); }