nested loop don't go inside each element c#

时间:2016-03-17 10:15:38

标签: c# matrix

Here is a part of what I wrote:

    double[,] visualmatrix = new double[3, m_descriptor.visualword.Length];

    for (int i=0; i<3; i++)
    {
        for (int j=0; j<m_descriptor.length; j++)
        {
          visualmatrix[i, j] = (m_descriptor.visualword[j].tf) * (m_descriptor.visualword[j].idf);
          System.Diagnostics.Debug.WriteLine(visualmatrix[i, j]);
        }
        Console.WriteLine();
    }

What I want for visual matrix in this case, is to fill visualmatrix[0,0] till visualmatrix[2,29] since m_descriptor.length is 29. But what is done that it fills just the first element of each i: visualmatrix[0,0],visualmatrix[1,0],visualmatrix[2,0].

1 个答案:

答案 0 :(得分:2)

我认为,你错过了.visualword的声明。将j<m_descriptor.length更改为j<m_descriptor.visualword.length

double[,] visualmatrix = new double[3, m_descriptor.visualword.Length];

for (int i=0; i<3; i++)
{
    for (int j=0; j<m_descriptor.visualword.length; j++)
    {
      visualmatrix[i, j] = (m_descriptor.visualword[j].tf) * (m_descriptor.visualword[j].idf);
      System.Diagnostics.Debug.WriteLine(visualmatrix[i, j]);
    }
    Console.WriteLine();
}