Blog

Convert C# to VB.NET

Aug 13

Written by:
Friday, August 13, 2010  RssIcon

 

In our company we do not program in VB.NET. Not that we have anything against it, we have just specialized in C# when we program .NET applications.

We are are aware that our WinForms libraries (DigitalRune Docking Windows and the DigitalRune Text Editor Control) are used by many VB programmers. And they regularly ask for VB example code.

Here are a few ways to automatically convert C# code to VB (or the other way around):

1. Free Online Tool

Here is an online tool that converts code snippets from one language to another:

http://www.developerfusion.com/tools/convert/csharp-to-vb/

It does not convert full projects.

2. Commercial Software

There is commercial software that translates C# to VB.NET. For example:

http://www.tangiblesoftwaresolutions.com/Product_Details/Instant_VB.html.

We haven't tried it because we prefer method number 3:

3. redgate's .NET Reflector (Free version)

If you don't know Reflector, go and get it right know (http://www.red-gate.com/products/reflector/). This is an important tool for every .NET programmer.

To see VB code load an assembly (e.g. SampleEditor.exe of the DigitalRune Text Editor Control). Right-click in the left tree view and select "Disassemble" to see the right code window. If you don't see VB code then choose "Visual Basic" in the tool bar.

Reflector_VB_ComboBox


You can also right-click in the left tree view to "Export…". This creates a solution with the VB code. The auto-converted code is not perfect but it is often a good start to create a final VB sample. In many cases it provides enough information so that a VB programmer with little C# experience can understand C# sample code.


Your name:
Gravatar Preview
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Security Code
CAPTCHA image
Enter the code shown above in the box below
Add Comment   Cancel