我尝试使用两个不同的构造函数在 C# 中创建类 Complex number,第一个构造函数采用实部和虚部,第二个构造函数采用模块和参数。
public class Complex
{
public Complex() { }
private Complex(double _re, double _im)
{
re = _re;
im = _im;
}
public static double Complex_FromCartesian(double _re, double _im)
{
return new Complex(_re, _im);
}
public static double Complex_FromPolar(double _mod, double _arg)
{
var _re = _mod * Math.Cos(_arg);
var _im = _mod * Math.Sin(_arg);
return new Complex(_re, _im);
}
public static Complex operator +(Complex num1, Complex num2)
{
return new Complex(num1.re + num2.re, num2.im + num2.im);
}
public static Complex operator -(Complex num1, Complex num2)
{
return new Complex(num1.re - num2.re, num2.im - num2.im);
}
public double Re { get; set; }
public double Im { get; set; }
private double re, im;
}
}
但是我在两个构造函数中都遇到了相同的错误
如何解决?