Convert C# to VB or Vice Versa with Visual Studio 2012
Posted
Tue, Aug 28 2012 22:39
by
Deborah Kurata
As .NET developers, we sometimes need to convert code from C# to VB or from VB to C#. Bing may have returned the perfect example of what you need, but it is in VB and you need C# code. Or some sample code you downloaded is in C# and you need it in VB. Whatever the case, Visual Studio 2012 now provides a tool for converting code between languages.
The Convert .NET tool is available from the Extensions and Updates (which were introduced in this prior blog post). Select Tools | Extensions and Updates. Then search for Convert .NET. Click Download to download and install it.

Instead of installing, however, the download option displays the Convert .NET Web site. After hunting around for a while, I found that clicking on the Version number at the bottom of the page next to a small download icon, downloaded the tool as a .zip file. You can then unzip it to run the executable.
When you launch the executable, the first drop down list allows you to select the type of conversion. Select C# <-> VB.NET Converter. In the second drop down list, select whether to go from C# to VB.NET or from VB.NET to C#.
Paste desired code in the top window and click Execute from the toolbar. The converted code then appears in the bottom window.

Note, however, that the conversion is often not perfect. For example, if you can read the above conversion, you'll notice that the first Dim statement that it generated in the VB code is not valid. So you may need to tune the converted code.
Use this tool as a starting point any time you need to convert code from C# to/from VB.NET.
Enjoy!