This is a migrated thread and some comments may be shown as answers.

"using" operator in C#

3 Answers 149 Views
Code Converter
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Valeri Hristov
Top achievements
Rank 1
Valeri Hristov asked on 30 Mar 2007, 02:41 PM

The converter is not able to convert code like this:

using (StreamWriter file = File.AppendText("C:\\temp\\file.txt"))
{
    file.WriteLine("Date: {0}", DateTime.Now);
}

which should become something like this (I translated the C# code to that format by hand and then threw it in the converter):

Dim file As StreamWriter = Nothing
Try
    file = File.AppendText("C:\temp\file.txt")
    file.WriteLine("Date: {0}", DateTime.Now)
Finally
    If file <> Nothing Then
        file.Dispose()
    End If
End Try

3 Answers, 1 is accepted

Sort by
0
Todd Anglin
Top achievements
Rank 2
answered on 30 Mar 2007, 06:13 PM
Valeri-

I'm not sure that the converter can make that judgment since the "Using" syntax is also valid in VB (just like the Try..Catch syntax is valid in C#). Microsoft introduced the Using syntax to VB in version 2.0, which means I think the converters output is correct.

What do you think?

Thanks~
Todd
0
Valeri Hristov
Top achievements
Rank 1
answered on 02 Apr 2007, 06:33 AM
My bad, I made a typo the first time, hence the error :)

However, I am always getting the following error:
0
Todd Anglin
Top achievements
Rank 2
answered on 02 Apr 2007, 06:33 PM
Valeri-

Thanks for brining my attention to the JavaScript error. The error was not happening in my dev environment, so I refreshed the production files and that seemed to clear things up. You should not run into that Tab Extender error any more.

Thanks~
Todd
Tags
Code Converter
Asked by
Valeri Hristov
Top achievements
Rank 1
Answers by
Todd Anglin
Top achievements
Rank 2
Valeri Hristov
Top achievements
Rank 1
Share this question
or