数组的第一个索引 returns 一个 IndexOutOfRangeException

First index of an array returns an IndexOutOfRangeException

我正在编写读取 CSV 文件(二维和所有数字)的 Unity 脚本,将其分解为附加到二维浮点数组的浮点数。这是我的代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LoadCalibration : MonoBehaviour
{
    public float[,] pc_array; // Reconstructed PC coefficient MD array (PCs as rows and variables as columns)

    // Start is called before the first frame update
    void Start()
    {
        // PC COEFFICIENTS

        pc_array = new float[20, 20];
        Debug.Log(pc_array);

        TextAsset pc_data = Resources.Load<TextAsset>("pc_coeff"); //Data is in as variables x PCs

        string[] variable = pc_data.text.Split(new char[] { '\n' }); // split pc_data into rows(each row is one variable, for all PCs)

        for (int i = 0; i < variable.Length - 1; i++)
        {
            string[] pc = variable[i].Split(new char[] { ',' }); // delegate each variable to a pc
            Debug.Log(i);

            for (int j = 0; j < pc.Length; i++)
            {
                Debug.Log(j);
                pc_array[j,i] = float.Parse(pc[j]); // Load float value into the pc_coeff MD array
            }

        }

    }
}

它抛出这个错误:

IndexOutOfRangeException: Index was outside the bounds of the array.
LoadCalibration.Start () (at Assets/Scripts/LoadCalibration.cs:31)

使用 Debug.Log() 我发现错误发生在 i = 0 和 j = 0(数组的第一个索引)处,即使我将其声明为 20 x 20 数组。我是 C# 的新手,所以很明显错误是什么,但我无法解决。任何帮助将非常感激!

我已经使用 Debug.Log() 来评估其余代码是否正常工作(也就是读取 CSV 文件并将每个字符串条目转换为单个浮点数)。

  for (int j = 0; j < pc.Length; i++)

改为

  for (int j = 0; j < pc.Length; j++)