Skip to content

Commit 95a015f

Browse files
authored
Fix increment and decrement static operator
The increment and decrement static operator currently are no-op. This fix ensure they actually do increment and decrement the value of the numerator in the fraction. Technically doing `operand.numerator + 1` would technically produce a more optimized IL but would not work any longer for a class version of Fraction. fix #48626
1 parent a574d62 commit 95a015f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

docs/csharp/language-reference/operators/snippets/shared/OperatorOverloading.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ public Fraction(int numerator, int denominator)
3636

3737
// Define increment and decrement to add 1/den, rather than 1/1.
3838
public static Fraction operator ++(Fraction operand)
39-
=> new Fraction(operand.numerator++, operand.denominator);
39+
=> new Fraction(++operand.numerator, operand.denominator);
4040

4141
public static Fraction operator --(Fraction operand) =>
42-
new Fraction(operand.numerator--, operand.denominator);
42+
new Fraction(--operand.numerator, operand.denominator);
4343

4444
public override string ToString() => $"{numerator} / {denominator}";
4545

0 commit comments

Comments
 (0)