Deborah's Developer MindScape






         Tips and Techniques for Web and .NET developers.

August 29, 2012

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

Filed under: C#,VB.NET,Visual Studio @ 12:39 am

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!

9 Comments

  1.   Shyh Hua Hung — August 31, 2012 @ 9:31 pm    Reply

    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

  2.   Ted — September 13, 2012 @ 9:04 am    Reply

    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#.

  3.   DeborahK — September 13, 2012 @ 3:22 pm    Reply

    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.

  4.   malathi — September 21, 2012 @ 5:44 am    Reply

    ok

  5.   Will Howard — October 26, 2012 @ 7:42 am    Reply

    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.

  6.   yash — December 29, 2012 @ 7:34 am    Reply

    my email id is send to mail

  7.   David Marshall — May 8, 2013 @ 4:33 pm    Reply

    http://channel9.msdn.com/Series/Windows-Store-apps-for-Absolute-Beginners-with-C-/Part-1-Series-Introduction

    Bob Tabor: “While I began with VB, I haven’t seen a lot of docs / videos / articles / books using VB for Win8 or other recent technologies. Increasingly, it feels to me *personally* like C# would be a good investment.”

    Sounds like Bob thinks VB.NET is on the way out.

  8.   Bahman — January 28, 2014 @ 6:39 am    Reply

    i need convert C# to vb.net

  9.   DeborahK — January 29, 2014 @ 11:15 am    Reply

    Hi Bahman – Were you able to try this extension? Or do you need to convert an entire project?

RSS feed for comments on this post. TrackBack URI

Leave a comment

© 2022 Deborah's Developer MindScape   Provided by WPMU DEV -The WordPress Experts   Hosted by Microsoft MVPs