所以我有两种形式。一个表单获取数字并计算一个复数并将其保存到form1数组。一切都正确传递和计算。我的复杂阵列没有问题。问题是当我尝试获得复数的阶段时。我知道大小和阶段是Complex结构的属性,所以我可以只执行load_Results.Magnitude或load_Results.Phase并获取相应的值,但它并没有给我选择将其作为属性。我是否在表单1中以错误的方式初始化它们?如何才能显示这些属性。
这就是我的错误:
Error 24 'System.Array' does not contain a definition for 'Magnitude' and no extension method 'Magnitude' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?)
表格1
public static double[] freqList;
public static Complex[] load_Results;
public form 1()
{ InitializeComponent();
freqList = new double[801];
load_Results = new Complex[801];
}
private void click_view(object sender, EventArgs e)
{ // part that fails
Graph.Series[0].Points.AddXY(freqList,load_Results.Magnitude);
}
表格2
private void test()
{
form1.load_Results[i] = Calculations(form1.freqList[i]);
}
public Complex Calculations(double freq)
{ Complex cval = new Complex();
double mag, phase;
//does math stuff to calculate mag and phase
cval = Complex.FromPolarCoordinates(mag, phase);
return (cval);
}
答案 0 :(得分:0)
load_Results是一个包含Complex类型元素的数组。您需要从该数组的每个元素获取Magnitude属性并返回该属性。例如:
Graph.Series[0].Points.AddXY(freqList, load_Results.Select(x => x.Magnitude).ToArray());