UPDATE I tried Crazy's solution but now I have problem showing data in a foreach loop:
foreach(double开发者_StackOverflow data in ztr.GetCurveDataForTestType())
{
richTextBox1.AppendText("Voltage" + data + " --------- ");
richTextBox1.AppendText("Current" + data + "\r\n");
}
That code prints out something like:
Voltage-0.175 --------- Current-0.175
Voltage-9.930625E-06 --------- Current-9.930625E-06
Voltage-0.171875 --------- Current-0.171875
Voltage-9.53375E-06 --------- Current-9.53375E-06
Voltage-0.16875 --------- Current-0.16875
how should I fix it?
Hi everyone,
I have an xml file that contains Voltage and Current values for a curve. I want to draw this curve so that Voltage is X and Current as Y in the cartesian coordinate.
I can get voltage and current values out of the XML file easily like the code below. But I want to know how can I return this values in a nice clean Array that I can use easily later.
Here is my code:
public double[,] GetCurveDataForTestType()
{
List<double> voltage = new List<double>();
List<double> current = new List<double>();
XPathNodeIterator volt = nav.Select("some XPATH");
XPathNodeIterator curr = nav.Select("some XPATH");
foreach (XPathNavigator value in volt)
{
voltage.Add(Convert.ToDouble(value.Value));
}
foreach (XPathNavigator value in curr)
{
current.Add(Convert.ToDouble(value.Value));
}
return null; //How should I reurn a nice array to use for drawing a curve(Voltage as X and current as Y)
}
How about this...
double[,] data = new double[voltage.Count(), 2];
for (int i = 0; i < voltage.Count(); i++)
{
data[i, 0] = voltage[i];
data[i, 1] = current[i];
}
Does it have to be an actual array? .Union() can give you one list. You could project them to an array with .Union.ToArray() if you really wanted to.
List is basicly array, you can access it by index [] so why not just use List. You also save your self the trouble of casting it.
To Fix your foreach loop just add indexer
foreach(double data in ztr.GetCurveDataForTestType())
{
richTextBox1.AppendText("Voltage" + data[0] + " --------- ");
richTextBox1.AppendText("Current" + data[1] + "\r\n");
}
精彩评论