sealz
sealz

Reputation: 5408

Cannot use Using Statement

I am using Visual Studio 2005 and am unable to use the "Using" statement. I have just moved some code over from a .net 4 application, but that does not seem to be the problem as it is still not usable in a new app.

Using sw as StreamWriter = new StreamWriter(userFile2)
    For each blah as blahblah in blah()
        sw.WriteLine(blah)
    sw.Close()
End Using

Error = Using is not declared I am lead to believe that it should work the exact same as in VB 2010.

Upvotes: 0

Views: 729

Answers (2)

Bala R
Bala R

Reputation: 108957

Seems compile fine for me (VS 2005/.Net 2.0). You are missing Next for the For Each. Also you don't have to explicitly call Close() for sw, the Using block take care of it.

Using sw as StreamWriter = new StreamWriter(userFile2)
    For each blah as blahblah in blah()
        sw.WriteLine(blah)
    Next
End Using

Upvotes: 1

DWRoelands
DWRoelands

Reputation: 4940

You mention that you are doing this in Visual Studio 2005. Are you working in .NET 1.1 or .NET 2.0? I don't believe that the USING keyword is available in .NET 1.1.

Upvotes: 0

Related Questions