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.

image

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.

image

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!

Filed under: , , ,

Comments

# Adding Tools to Visual Studio 2012

Wednesday, August 29, 2012 12:59 AM by Deborah's Developer MindScape

One of the very nice things about Visual Studio is that all of the tools you need are in one place. With

# Friday Five–August 31, 2012

Friday, August 31, 2012 3:08 PM by The Microsoft MVP Award Program Blog

1. PPT 2013 - Resume Viewing When Reopening Presentation By Powerpoint MVP Troy Chollar  2. Convert

# re: Convert C# to VB or Vice Versa with Visual Studio 2012

Friday, August 31, 2012 9:31 PM by Shyh Hua Hung

The latest version of Convert.Net was examined with VirusTotal that reported it infected with a suspicious virus by MaCafee engine.  I am downloading the latest version today.

2012/9/1.

Please refer to this web page at:

http://tinyurl.com/d6bwfa2

# re: Convert C# to VB or Vice Versa with Visual Studio 2012

Thursday, September 13, 2012 9:04 AM by Ted

Please give an example of how well it converted , how many compiler errors were found, etc., when converting a project with 5000+ lines in multiple source files all in a single project.  We want to finish converting the last few VB.net applications entirely over to C#.

# re: Convert C# to VB or Vice Versa with Visual Studio 2012

Thursday, September 13, 2012 3:22 PM by Deborah Kurata

Hi Ted -

I would not use this tool for converting entire projects. Rather, it is best suited for converting code snippets. For example, you find some code in a blog post and need to convert it from VB to C# or vice versa.

Hope this helps.

# re: Convert C# to VB or Vice Versa with Visual Studio 2012

Friday, September 21, 2012 5:44 AM by malathi

ok

# re: Convert C# to VB or Vice Versa with Visual Studio 2012

Friday, October 26, 2012 7:42 AM by Will Howard

I don't see it available for VS Express for Desktop.

Would be a great learning tool, as well as a practical tool as the article states.

Leave a Comment

(required) 
(required) 
(optional)
(required) 
If you can't read this number refresh your screen
Enter the numbers above: