c#将参数传递给另一种方法

我正在尝试定义一个用于绘制图形的辅助类,我被告知使用Zip方法将数组X和Y的每个元素传递给另一个方法,但它没有很好地解决,可以任何专家点我做错了什么? 我找不到使用谷歌的任何类似情况。

或者只是我过于富有想象力,这种方式根本无法解决? 我已经看到了使用Zip方法计算x,y点对的示例,但没有作为参数传入。

情况:我的程序有2个函数和1个委托,第一个叫做PlotXYAppend的函数用来调用委托PlotXYDelegate然后传入方法Points.addXY进行绘图,我之所以使用chart.Invoke这里是针对线程的安全理由。

但我遇到的问题是委托或plotxyappend一次只取一对点,所以我想出了一个方法,即创建另一个名为PlotXYPass的函数,将一对XY点传递给plotxyappend来获取它工作,但我认为有一些我无法解决的问题,知识分子告诉我他们不喜欢我放在这个function中的参数。

我非常感谢任何帮助。

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms.DataVisualization.Charting; namespace LastTrial { public class PlotHelper { double[] X = { 1, 2, 3, 4, 5, 6 }; double[] Y = { 1, 2, 3, 4, 5, 6 }; Chart chart;// declare chart as chart type Series dataSeries;// declare dataSeries as Series type private delegate int PlotXYDelegate(double x, double y); private void PlotXYAppend(Chart chart, Series dataSeries, double x, double y) { chart.Invoke(new PlotXYDelegate(dataSeries.Points.AddXY), new Object[] { x, y }); }// this line invokes a Delegate which pass in the addXY method defined in Points, so that it can plot a new point on a chart. private void PlotXYPass(double[] X, double[] Y) { X.Zip(Y, (x, y) => this.PlotXYAppend(chart,dataSeries,x,y)); } // trying to pass in x,y points by extracting pairs of points from list []X and []Y into the function above which only takes a pair of x,y points } } 

 private object PlotXYAppend (Chart chart, Series dataSeries, double x, double y) { return chart.Invoke(new PlotXYDelegate(dataSeries.Points.AddXY), new Object[] { x, y }); } public IEnumerable PlotXYPass (double[] X, double[] Y) { return X.Zip(Y, (x, y) => this.PlotXYAppend(this.chart, this.dataSeries, x, y)); } 

然后在通话时删除懒惰,如:

 var ph = new PlotHelper(); ph.chart = this.chart; ph.dataSeries = this.chart.Series[0]; var result = ph.PlotXYPass(ph.X, ph.Y).ToList();