0
請幫幫我!我寫了下面的程序,有一個錯誤「變量」arr「之前使用...」我試圖修復,但我不能。請幫助我:)非常感謝!Visual Basic錯誤「變量之前使用......」
Imports System
Imports System.IO
Class Test
Public Shared Sub Main()
Try
' Create an instance of StreamReader to read from a file.
Dim sr As StreamReader = New StreamReader("a.txt")
Dim line As String
Dim arr()() As Char
Dim tem As Integer
tem = 1
' Read and display the lines from the file until the end
' of the file is reached.
Do
line = sr.ReadLine()
arr(tem) = line.ToCharArray
Console.WriteLine(Line)
Loop Until line Is Nothing
sr.Close()
Catch E As Exception
' Let the user know what went wrong.
Console.WriteLine("The file could not be read:")
Console.WriteLine(E.Message)
End Try
End Sub
End Class
Module Module1
Sub Main()
Test.Main()
End Sub
End Module
之前幹什麼用的?你明白錯誤的含義嗎? – SLaks 2012-04-19 20:34:56
請注意,你剛剛(很差)重新發明'File.ReadAllLines()'。 – SLaks 2012-04-19 20:37:21
警告\t \t 1變量「改編」它已經被分配了值之前被使用。運行時可能會導致空引用異常。而且我明白,但我無法找到修復它的方法 – smile232 2012-04-19 20:37:50