如何在 Visual Basic 中使用 while 循环从 StreamReader 中读取数据?

hat*_*mil 2 vb.net

考虑:

Dim line As String
Using readFile As New StreamReader(SalesUpdateFile)

While (line = readFile.ReadLine) IsNot Nothing
Run Code Online (Sandbox Code Playgroud)

我是 Visual Basic 新手。每次我运行此代码时都会出现此错误:

“IS”需要具有引用类型的操作数

我该如何解决这个问题?

Hei*_*nzi 5

虽然 Konamiman 的答案非常好,但我不喜欢重复自己,因此更喜欢以下模式以避免重复调用ReadLine()

Do
    Dim line = reader.ReadLine()
    If line Is Nothing Then Exit Do
    ' Process the line
Loop
Run Code Online (Sandbox Code Playgroud)