@@ -16,7 +16,8 @@ namespace Fractions
1616 /// <remarks>
1717 /// The the numerator and denominator are both Int64 (long).
1818 /// </remarks>
19- public struct Fraction : IRational
19+ [ Serializable ]
20+ public class Fraction : IRational
2021 {
2122 /// <summary>
2223 /// Gets or sets the numerator.
@@ -49,12 +50,21 @@ public long Denominator
4950 }
5051
5152 private long _denominator ;
52-
53+
54+ /// <summary>
55+ /// Create a fraction equal to one (1/1).
56+ /// </summary>
57+ public Fraction ( )
58+ {
59+ Numerator = 1 ;
60+ Denominator = 1 ;
61+ }
62+
5363 /// <summary>
5464 /// Create a fraction from another.
5565 /// </summary>
5666 /// <param name="f">The other fraction.</param>
57- public Fraction ( Fraction f ) : this ( )
67+ public Fraction ( Fraction f )
5868 {
5969 Numerator = f . Numerator ;
6070 Denominator = f . Denominator ;
@@ -64,7 +74,7 @@ public Fraction(Fraction f) : this()
6474 /// Create a fraction with a numerator.
6575 /// </summary>
6676 /// <param name="numerator">The numerator.</param>
67- public Fraction ( long numerator ) : this ( numerator , 1 ) // our constructor
77+ public Fraction ( long numerator ) : this ( numerator , 1 )
6878 {
6979 }
7080
@@ -76,19 +86,22 @@ public Fraction(long numerator) : this(numerator, 1) // our constructor
7686 public Fraction ( long numerator , long denominator )
7787 {
7888 Numerator = numerator ;
79- _denominator = denominator ;
89+ Denominator = denominator ;
8090
8191 FractionChecker ( ) ;
8292 }
8393
8494 /// <summary>
85- /// Create a fraction from dividing two others.
95+ /// Create a fraction from the result of dividing two others.
8696 /// </summary>
8797 /// <param name="fractA">The first fraction.</param>
8898 /// <param name="fractB">The second fraction.</param>
8999 public Fraction ( Fraction fractA , Fraction fractB )
90100 {
91- this = fractA / fractB ;
101+ var tmp = fractA / fractB ;
102+
103+ Numerator = tmp . Numerator ;
104+ Denominator = tmp . Denominator ;
92105
93106 FractionChecker ( ) ;
94107 }
0 commit comments