Operator overloading is so you can use the standard operators (+, -, *, /) with custom types.
Code:public struct ComplexNumber { public double Real { get; set; } public double Imaginary { get; set; } public static ComplexNumber operator + (ComplexNumber left, ComplexNumber right) { return new ComplexNumber { Real = left.Real + right.Real, Imaginary = left.Imaginary + right.Imaginary }; } } var a = new ComplexNumber (1, 2); var b = new ComplexNumber (3, 4); // 'c' is now the complex number (4, 6) var c = a + b;




Reply With Quote
