0

我有几个输入框,我想将所有这些值存储在二维数组中,然后全部写入 txt 文件,这是因为我想知道值的 i,j。因此,如果我进行一些更改,我只会看一下这个数组,那么如何在 txt 文件中插入一个数组呢?

我在做

Dim mArray(100,100) As String

mArray(0,0) = Textbox1.Text
mArray(0,1) = Textbox2.Text
...



Dim objWriter As New System.IO.StreamWriter("c:\file.txt", False)
objWriter.WriteLine(mArray)
objWriter.Close()

还是这样做会更好:

Dim objWriter As New System.IO.StreamWriter("c:\file.txt", False)
objWriter.WriteLine(Textbox1.Text)
objWriter.WriteLine(Textbox2.Text)
objWriter.WriteLine(Textbox3.Text)
objWriter.WriteLine(Textbox4.Text)
...
objWriter.WriteLine(Textboxn.Text)

objWriter.Close()
4

1 回答 1

2

我不知道二维数组,但对于一维数组,这里是代码:

Dim mArray(100) as string
mArray(0) = TextBox1.Text
.
.
.
.

For I as integer = 0 to mArray.count - 1
    Dim objWriter As New System.IO.StreamWriter("c:\file.txt", False)
    objWriter.WriteLine(mArray(I))
    objWriter.Close()
Next I

我认为对于二维数组,您需要使用嵌套的类似

For I as integer = 0 to ...........
    For J as integer = 0 to ..........
        Dim objWriter As New System.IO.StreamWriter("c:\file.txt", False)
        objWriter.WriteLine(mArray(I,J))
        objWriter.Close()
    Next J
next I
于 2013-05-15T20:31:02.573 回答