2012-04-19 11 views
0

私を助けてください!私は次のプログラムを書いたが、間違いがある "Variable" arr "が以前に使われていた..."修正しようとしましたが、できませんでした。助けてください:)ありがとう!視覚的な基本的なエラー "変数は...の前に使用されています"

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 
+0

何の前に使われますか?エラーの意味を理解していますか? – SLaks

+2

'File.ReadAllLines()'を再開発したばかりです。 – SLaks

+0

警告変数 'arr'は、値が割り当てられる前に使用されます。実行時にnull参照例外が発生する可能性があります。そして私は理解しますが、私はそれを修正する方法を見つけることができませんでした – smile232

答えて

1

arr変数を初期化する必要があります。

アレイの大きさがわからないので、代わりにList(Of T)を使用してください。

+0

ありがとう:)私はそれを得た:) – smile232

関連する問題