public double Real { get; }
public double Imaginary { get; }
public Complex(double real, double imaginary)
public static Complex operator +(Complex a, Complex b)
return new Complex(a.Real + b.Real, a.Imaginary + b.Imaginary);
public static Complex operator -(Complex a, Complex b)
return new Complex(a.Real - b.Real, a.Imaginary - b.Imaginary);
public static Complex operator *(Complex a, Complex b)
double realPart = a.Real * b.Real - a.Imaginary * b.Imaginary;
double imagPart = a.Real * b.Imaginary + a.Imaginary * b.Real;
return new Complex(realPart, imagPart);
public static Complex operator /(Complex a, Complex b)
double denominator = b.Real * b.Real + b.Imaginary * b.Imaginary;
double realPart = (a.Real * b.Real + a.Imaginary * b.Imaginary) / denominator;
double imagPart = (a.Imaginary * b.Real - a.Real * b.Imaginary) / denominator;
return new Complex(realPart, imagPart);
public override string ToString()
return $"{Real} + {Imaginary}i";
return $"{Real} - {-Imaginary}i";
static void Main(string[] args)
Complex z1 = new Complex(2, 6);
Complex z2 = new Complex(8, 4);
Console.WriteLine($"({z1}) + ({z2}) = {z1 + z2}");
Console.WriteLine($"({z1}) - ({z2}) = {z1 - z2}");
Console.WriteLine($"({z1}) * ({z2}) = {z1 * z2}");
Console.WriteLine($"({z1}) / ({z2}) = {z1 / z2}");