我有图表系列:
Series[] tempSeries = new Series[sensorNum]; // Series to hold current/past temperature data for plotting, for each sensor
我向他们添加新点:
tempSeries[i].Points.AddXY(current_time, temp_F[i]); // Add new temperature data to series
现在我想将系列转换为字符串以通过套接字发送。
问题是如何从系列中获得Y值?
我试过了:
private string sendAll() {
string myMsg = "";
double[,] lastTemp = new double[4, 1200];
double[,] lastWind = new double[4, 1200];
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 1200; j++){
try
{
lastTemp[i, j] = tempSeries[i].Points[j].YValues[0];
myMsg += lastTemp[i, j] + " ";
}
catch (Exception ex) {
lastTemp[i, j] = 0;
myMsg += 0 + " ";
}
}
}
myMsg += "; ";
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 1200; j++)
{
try
{
lastWind[i, j] = windSeries[i].Points[j].YValues[0];
myMsg += lastWind[i, j] + " ";
}
catch (Exception ex)
{
lastWind[i, j] = 0;
myMsg += 0 + " ";
}
}
}
MessageBox.Show(myMsg);
return myMsg;
}
但我的节目很冷......
答案 0 :(得分:1)
也许这不是你的代码唯一的问题,但你永远不应该在循环中使用字符串连接(myMsg += 0 + " ";
...)因为字符串是不可变的。请改用StringBuilder
课程。像这样:
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 10000; i++)
{
sb.Append("x");
}
string x = sb.ToString();
以下是有关字符串不可变的原因及其后果的详细信息: http://en.morzel.net/post/2010/01/26/Why-strings-are-immutable-and-what-are-implications-of-it.aspx