Possible Duplicate:
How do I read from a StreamReader with a while loop in Visual Basic?
In C# I would loop a streamreader as shown below.
while ((line = reader.ReadLine()) != null)
{
list.Add(line); // Add to list.
Console.WriteLine(line); // Write to console.
}
What’s the Equivalent in VB.NET?
I tried
while ((line = reader.ReadLine()) IsNot Nothing)
But it is not working.
In C#,
((line = reader.ReadLine()) != null)is an assignment inside an expression. VB does not support that. Thus, you will have to splitline = reader.ReadLine()andline != null(in VB:line IsNot Nothing)There are many ways to do that. One has been presented by Prasanna in a parallel answer. This is the one I’d prefer, since you do not need to repeat the
ReadLinecall: