Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#GetLength 2D数组。索引超出了数组的边界_C#_Visual Studio 2017 - Fatal编程技术网

C#GetLength 2D数组。索引超出了数组的边界

C#GetLength 2D数组。索引超出了数组的边界,c#,visual-studio-2017,C#,Visual Studio 2017,我打算使用GetLength()获得数组第二维度的长度 我使用GetLength(0)读取第一个维度,使用GetLength(1)读取第二个维度 资料来源: 但是,这对我不起作用,并引发:System.IndexOutOfRangeException:“索引超出了数组的边界。”尝试访问第二个维度时(使用第二个for循环) 下面是我正在使用的代码片段 List<string> barDates = new List<string>(); List<s

我打算使用
GetLength()
获得数组第二维度的长度

我使用
GetLength(0)
读取第一个维度,使用
GetLength(1)
读取第二个维度

资料来源:

但是,这对我不起作用,并引发:
System.IndexOutOfRangeException:“索引超出了数组的边界。”
尝试访问第二个维度时(使用第二个
for循环

下面是我正在使用的代码片段

List<string> barDates = new List<string>();

        List<string> barValues = new List<string>();

        for (int i = 0; i < data.GetLength(0); i++)
        {
            MessageBox.Show(data[i][0] + " " + data[i][1]);

            for (int x = 2; x < data.GetLength(1) - 2; x++)
            {
                int value = 0; 

                value = value + Int32.Parse(data[i][x]);

                barValues.Add(value.ToString());
            }

            barDates.Add(data[i][1]);
        }

        barValues.ToArray();

        barDates.ToArray();
List barDates=新列表();
List barValues=新列表();
for(int i=0;i
以下是变量
数据
,其值如下:

其主要目标是读取包含14列的
.csv
文件,第一列是企业名称,第二列是第二个
for loop
中不需要的年份

请忽略
MessageBox.Show(数据[i][0]+“”+数据[i][1])正如我所说,我只是想看看是否处理了正确的值

行的数量是不断变化的,因此需要是动态的

维度2中的所有数字将相加,然后添加到每行的数组中

然后,该数组将在条形图中使用

这是一个锯齿状阵列<代码>数据。GetLength(1)
将不起作用,因为数据没有第二维度。改用这个:

data[i].Length
这是一个锯齿状阵列<代码>数据。GetLength(1)
将不起作用,因为数据没有第二维度。改用这个:

data[i].Length