예제 #1
0
        public static Fraction operator +(Fraction p1, Fraction p2)
        {
            Fraction newFraction = new Fraction(p1.Numerator, p1.Denominator);
            newFraction.Numerator = newFraction.Numerator * p2.Denominator + p2.Numerator * newFraction.Denominator;
            newFraction.Denominator = newFraction.Denominator * p2.Denominator;

            return newFraction;
        }
예제 #2
0
        static void Main(string[] args)
        {
            Fraction oneHalf = new Fraction(1, 2);
            Fraction oneQuarter = new Fraction(1, 4);

            Fraction overLoadedFraction = oneHalf + oneQuarter;

            Console.WriteLine("{0} + {1} = {2}", oneHalf.ToString(), oneQuarter.ToString(), overLoadedFraction.ToString());
        }