Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.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
Arrays 如何将字符串内容附加到数组中_Arrays_Vb.net - Fatal编程技术网

Arrays 如何将字符串内容附加到数组中

Arrays 如何将字符串内容附加到数组中,arrays,vb.net,Arrays,Vb.net,我已经编写了代码,但有个问题。编译器向我显示以下消息: 对象引用未设置为对象的实例。 代码如下: Dim array As List(Of String) For Each row As DataGridViewRow In DataGridView1.Rows If Not row.IsNewRow Then array.Add(row.Cells(0).Value.ToString & "," & row.Cells(1).Value.

我已经编写了代码,但有个问题。编译器向我显示以下消息:

对象引用未设置为对象的实例。 代码如下:

Dim array As List(Of String)
For Each row As DataGridViewRow In DataGridView1.Rows
        If Not row.IsNewRow Then
            array.Add(row.Cells(0).Value.ToString & "," & row.Cells(1).Value.ToString & _
                            row.Cells(2).Value.ToString & "," & row.Cells(3).Value.ToString)
        End If
    Next
出现问题的行是array.add


有什么问题吗?

当您使用列表时,必须使用新的:


正如Idle_Mind提到的,使用数组作为变量名是个坏主意。它很混乱,代码也很难阅读。

您没有实例化列表。将Dim数组更改为ListOf字符串,将Dim数组更改为新ListOf字符串。顺便说一下,变量名太可怕了……或者尝试使用Dim数组作为新的ArrayList。然后使用array.add
Dim array As New List(Of String)