I have the following code:
List<Point> xyData = new List<Point>();
for (int i = 0; i < xdata.Length;i++ )
{
xyData.Add(new Point(xdata[i], ydata[i]));
}
I want to iterate simultaneously over xdata and ydata, which have the same length
Now, I can add another counter,
int i=0;
List<Point> xyData = new List<Point>();
foreach (double x in xdata){
var y = ydata[i];
xyData.Add(new Point(x, y));
}
But I want to write something like this (Pseudo code, does not compile)
List<Point> xyData = new List<Point>();
foreach (double x in xdata, double y in ydata){
xyData.Add(new Point(x, y));
}
Is there an elegant way to achieve what I want?
Edit:
I meant that I want to get a list like this:
[x0,y0],[x1,y1],[x2,y2].
Sorry for the ambiguity.
Use LINQ.
If you want the Carthesian product (x1,y1) (x1,y2) (x2,y1) (x2,y2)
If you want the merged list (x1,y1) (x2,y2)