我正在尝试打印各种foreach循环的ArrayList的内容,但我唯一得到的是String + System.Collections.ArrayList.
例如,以下代码:
ArrayList nodeList = new ArrayList();
foreach (EA.Element element in elementsCol)
{
if ((element.Type == "Class") || (element.Type == "Component") || (element.Type == "Package"))
{
nodeList.Add(element);
}
Console.WriteLine("The nodes of MDG are:" + nodeList); //stampato a schermo la lista dei nodi nel MDG finale
Run Code Online (Sandbox Code Playgroud)
我得到的输出是:
The nodes of MDG are:System.Collections.ArrayList
请有人告诉我为什么?
我的目标是使三重for循环乘以矩阵X矩阵,我得到输入矩阵,我必须得到矩阵^ 2.
我收到错误"IndexOutOfRangeException" - 当我调试以下代码时,索引超出了数组的范围:
for (int i = 1; i < nodeList.Count+1; i++)
{
for (int j = 1; j < nodeList.Count+1; j++)
{
result[i, j] = "0";
for (int k = 1; k < nodeList.Count+1; i++)
{
if ((matrix[i, k] != null) && (matrix[k, j] != null))
{
n1 = Convert.ToInt32(matrix[i, k]);
n2 = Convert.ToInt32(matrix[k, j]);
n3 = Convert.ToInt32(result[i, j]);
total = n3 + n1 * n2;
_total = total.ToString();
result[i, j] = _total;
}
}
}
} …Run Code Online (Sandbox Code Playgroud)