我看到了很多与问题有关的主题:
“对象不包含 X 的定义,并且没有扩展方法 X 接受对象类型的第一个参数”
但是他们都没有解决我的问题。
情况:我想保存 3 个系列的数据点。因此,我制作了一个包含该系列的列表:
List<OxyPlot.Series.DataPointSeries> filesToBeStored;
public OxyPlot.Series.DataPointSeries saveAnalyseBSITotal;
public OxyPlot.Series.DataPointSeries saveAnalyseSBSI;
public OxyPlot.Series.DataPointSeries saveAnalyseTBSI;
在 Form.cs 中,我调用 SaveFile(...):
for (int i = 0; i < plotSBSIBandsA.Model.Series.Count; i++)
{
OxyPlot.Series.DataPointSeries sA = (plotSBSIBandsA.Model.Series[i] as OxyPlot.Series.DataPointSeries);
OxyPlot.Series.DataPointSeries sB = (plotSBSIBandsB.Model.Series[i] as OxyPlot.Series.DataPointSeries);
sB.Points.Clear();
for (int j = 0; j < sA.Points.Count; j++)
{
sB.Points.Add(new OxyPlot.DataPoint(sA.Points[j].X, sA.Points[j].Y));
}
}
if(saveButtonClicked)
{this.SaveFile(sB)}
完整的 Save-Class 是:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BSIAnalyzer
{
class SaveFile
{
List<OxyPlot.Series.DataPointSeries> filesToBeStored;
public OxyPlot.Series.DataPointSeries saveAnalyseBSITotal;
public OxyPlot.Series.DataPointSeries saveAnalyseSBSI;
public OxyPlot.Series.DataPointSeries saveAnalyseTBSI;
public SaveFile(OxyPlot.Series.DataPointSeries sA)
{
for (int i = 0; i < sA.Points.Count; i++)
{
saveAnalyseBSITotal.Points.Add(new OxyPlot.DataPoint(sA.Points[i].X, sA.Points[i].Y));
}
}
public SaveFile(List<OxyPlot.Series.DataPointSeries> series)
{
filesToBeStored.Insert(0, saveAnalyseBSITotal);
filesToBeStored.Insert(1, saveAnalyseSBSI);
filesToBeStored.Insert(2, saveAnalyseTBSI);
for (int k = 0; k < series.Count; k++)
{
filesToBeStored[k].Points.Add(new OxyPlot.DataPoint(series[k].Points.X, series[k].Points.Y));
}
}
}
}
在带有 te "k" 的 forloop 中我得到了错误。