Tuesday, March 22, 2011

Using and StreamReader (C# and VB)

Code Samples in VB.NET and C# using the System.IO.StreamReader object with the -Using- statement.
// c#
using System.IO
        
using (StreamReader reader = new StreamReader(filenamepath))
{
    while (!reader.EndOfStream)
    {
        Console.WriteLine(reader.ReadLine();
    }
}
// vb.net
Imports System.IO
        
Using reader As StreamReader = New StreamReader(filenamepath)
    While Not reader.EndOfStream()
        Console.WriteLine(reader.ReadLine())
    End While
End Using

No comments:

Post a Comment