110,535
社区成员
发帖
与我相关
我的任务
分享
for (int i = 0; i < Selection.ItemCount; i++)
{
comp = (IvcComponent)Selection.getItem(i);
object name = comp.getProperty("Name");
double[] matrix = (double[])comp.RootNode.getProperty("WorldPositionMatrix"); //获得坐标xyz
if (textBox5.Text != "")
{
textBox5.Text += "->" + name.ToString();
}
else
{
textBox5.Text = name.ToString();
}
string[] tmp = textBox5.Text.Split("->".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); //得到拆分项
double sum = 0;
for (int x = 0; x < tmp.Length; x++)//根据拆分项确定行数
{
b[x][0] = matrix[0];
b[x][1] = matrix[1];
b[x][2] = matrix[2];
double xd = b[x][0] - b[x + 1][0];
double yd = b[x][1] - b[x + 1][1];
double zd = b[x][2] - b[x + 1][2];
sum += Math.Sqrt(xd * xd + yd * yd + zd * zd);
//listBox1.Items.Add("distance = " + sum);
}
}
和楼上说的一样吗? b[x]的问题。
b[x]的问题。
应该是x超过了b的数组长度。 b的长度是在哪定的? tmp.Length是会变的,但没发现b的长度跟着变,除非b定义时就很长。
double[][] b = { };
b当作一个全局变量来用的,怎么定义啊你在哪里检查了 b 的第一维长度 大于等于 tmp.Length 了? 既然没检查,就不能怪 b[x+1] 越界了