Click here to Skip to main content
Click here to Skip to main content

.NET Code Conversion - Convert your code

By , 4 Feb 2012
 

Table of Contents

Introduction

This post explains how to convert the code in .NET.

Background

In lot of programming forums, you can find some questions related to code conversion. For example an enquirer asking a question in VB.NET & answerer(s) posting solution(s) but unfortunately its in C#(instead of VB.NET). After seeing the solution(s), the enquirer replying some thing like "My project developed in VB.NET but your solution is in C#, blah blah blah ....". Then answerer's reply will be something like "You can convert the code, search in web for code convertors". But sometimes Enquirer wants an offline convertor(Reason may be the Internet connection). So this simple post would be useful for them.

SharpDevelop

It's an Open Source Development Environment for .NET. You can download the tool here. Also take a look at the features of SharpDevelop & they have forum so if you have any questions that will help you. Using this you can convert the code.

Supported Programming Languages
For Code conversion, currently SharpDevelop supports the following languages.
  • C#
  • VB.NET
  • Boo
  • Python
  • Ruby
Code Conversion

After installation, create a blank project & write some code. Here I have written some C# code. Now click Tools menu, select option Convert code to & select the language which you want(Here I have selected VB.NET). That's all. Now the code has been converted & generated in new file.

C# Code

C#.NET Code

VB.NET Code

VB.NET Code

Online Convertors - Alternative way

Offline Convertors

Addin(s)/Web services

Addins created from online code conversion Web services.

A Visual Studio Add-In That Converts C# Code To Visual Basic

Before Conversion

Make sure your code is working, for example if you miss single { or anyother things then the conversion will show you syntax error(s) instead of output. See below.

The converter uses SharpDevelop's NRefactory to perform the conversion. For the conversion to work properly, you have to paste a full class or source code file because we don't do "magic" RegEx's or string replacement - our code converter uses a full blown parser, and that's why the source code must be valid.

Even convertors won't convert the code 100%. The main reason is some features doesn't exist in particular language, see the Further reading section. Even Commertial tools convert the code only 99% Or probably you need to code rewrite.

Remember, If you want convert VB6 to C# don't go with that option. Convert VB6 to VB.NET using VS wizard & make sure the code is working and then do VB.NET to C#

Code Rewrite

Read about Rewrite (programming) & check this post Rewrite Code From Scratch which contains good & bad reasons to avoid/code-rewrite.

Multiple Programming Languages in .NET

Alternatively you can use both code in your application if you don't want to convert the code, see below.

VB6 to .NET

VB6 is obsolete by a decade and was always horrible.[^]
Why is anyone still using VB6 in 2011 ? Self loathing ? A dinosaur who refused to move with the times ?[^]
VB6 is dead and was always a joke. Why are you using it ? [^]

In VS, You have a wizard to convert VB6 to VB.NET. AFAIK, There is no freeware to convert VB6 to VB.NET. BTW even if you convert the code using convertor, it won't do that 100%, you must need to do some/more manual changes. Particularly if you used any 3rd party components then it will be a big headache because they(3rd parties) always changing the things in every version, so the VB6 code will show syntax error(s) in VB.NET. Check this bunch.

ASP to .NET

Java to .NET

  • Java Language Conversion Assistant 2.0 - Java Language Conversion Assistant is a tool that automatically converts existing Java-language code into Visual C#
    Retirement of J# language and Java Language Conversion Assistant from future versions of Visual Studio Since customers have told us that the existing J# feature set largely meets their needs and usage of J# is declining, Microsoft is retiring the Visual J# product and Java Language Conversion Assistant tool to better allocate resources for other customer requirements. The J# language and JLCA tool will not be available in future versions of Visual Studio. To preserve existing customer investments in J#, Microsoft will continue to support the J# and JLCA technology that shipped with Visual Studio 2005 through to 2015 as per our product life-cycle strategy.
  • Janett - Java to .Net Translator - Janett translates Java syntax, constructs and calls to Java libraries to C# / .Net counterparts.
  • CSharpJavaMerger Framework - Free and open source C# and Java conversion tool.
  • Java 2 CSharp Translator for Eclipse - That tool makes it possible to automatic translate Eclipse java projects into Visual Studio projects. Generated code can be directly compiled and executed whitout any user modification.

PHP to .NET

Delphi to .NET

  • Delphi.NET - is a collection of Open Source tools and code components that enable Borland Delphi (version 5 or higher) to communicate with the Microsoft .NET-Framework.

C++ to .NET

ColdFusion to .NET

Videos

Further Reading

History

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

thatraja
Web Developer
India India
Member
Programmer | CodeProject MVP, Mentor | Author | Geek | Blogger | Bachelor | Dude
 
About him & his blog? check out here.
 
In Codeproject, he posted a blogpost & more than couple of Tip/Tricks, hope he'll write more soon. And he got a place in CCC table.
 
In programming, he wants to go with new things like HTML5, CSS3, WP7, Silverlight, WPF, WCF, etc.,
 
His hobbies are watching movies, Codeproject, being alone, etc.,

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionIt does convert only new solutions !memberRenganathan Iyengar16 May '13 - 22:48 
A very simple, nice and useful article which gives a clear intro and a strong case for switching over to sharp develop IDE.
 
I am happy with even the code conversions, but it does convert only new projects created inside it..it just not show even the menu under the tools menu.
 
Can something be done for converting the solutions already created outside the SD IDE ? This will bring lots of smiles to vb.net users like who otherwise make pilgrimage to the developerfusion.com tool for converting file by file..
 
Looking forward to more of these converters.. Big Grin | :-D
 
Renga
GeneralMy vote of 5memberTarek Elqusi24 Jan '13 - 21:06 
Good work, this idea is really useful.
GeneralMy vote of 5memberyeng thao19 Jan '13 - 2:02 
Nice
GeneralMy vote of 5mvpAbhinav S7 Jan '13 - 19:47 
Nice.
QuestionC# to VB.net Code Convertormembercarlmalden28 Jul '12 - 11:30 
This is a good one.
 
https://namegin.com/Secure/CodeConvert.aspx[^]
Thanks,
Carl

QuestionJust noticed something...memberNaerling15 Jul '12 - 1:19 
I was Googling for ".NET code" and this was the second search result.
The first one was CodeProject.com Big Grin | :-D
 
How cool is that!?
 
By the way, how's your article coming along? Still looking forward to it.
I recently wrote a new one. If you're interested: A Look under the hood of the .NET Framework[^].
It's an OO world.
public class Naerling : Lazy<Person>{
    public void DoWork(){ throw new NotImplementedException(); }
}

AnswerRe: Just noticed something...mvpthatraja20 Jul '12 - 10:44 
Naerling wrote:
I was Googling for ".NET code" and this was the second search result.

The first one was CodeProject.com Big Grin | :-D
 

How cool is that!?
Smile | :) Glad to see that. Also some other guys informed me the same thing.
Naerling wrote:
By the way, how's your article coming along? Still looking forward to it.
Yep, I'm spending time for that whenever free. Surely will inform you all. Fixed the target - August 2012.
Naerling wrote:
I recently wrote a new one. If you're interested: A Look under the hood of the .NET Framework[^].
Already It's in my bookmarks, I'm middle of reading that, will give you feedback after my reading.

GeneralRe: Just noticed something...memberNaerling22 Jul '12 - 11:14 
thatraja wrote:
Fixed the target - August 2012
Marked on my calendar Wink | ;)
thatraja wrote:
will give you feedback after my reading
Looking forward to your opinion Smile | :)
It's an OO world.
public class Naerling : Lazy<Person>{
    public void DoWork(){ throw new NotImplementedException(); }
}

GeneralMy vote of 5memberCarsten V2.07 Jul '12 - 19:39 
Thank you for sharing!
GeneralMy vote of 4memberfredatcodeproject7 Jun '12 - 23:13 
good article
thanks
GeneralMy vote of 5mvpSAKryukov5 Jun '12 - 17:29 
Nice useful collection.
—SA

GeneralMy vote of 5memberEg-FOFO9 Apr '12 - 5:12 
After searching for hours i found this article and saved me a lot of time searching about this, thanks
GeneralMy vote of 5mvpEspen Harlinn8 Apr '12 - 0:56 
Nice article Big Grin | :-D
GeneralMy vote of 5memberSChristmas2 Apr '12 - 22:40 
Nice blog thatraja. Finally you have written a blog/article.
GeneralMy vote of 5memberMonjurul Habib13 Mar '12 - 10:49 
great Thumbs Up | :thumbsup:
GeneralMy vote of 5memberProEnggSoft7 Mar '12 - 15:19 
Nice article. All references regarding code conversion given at one place
QuestionAnd reference it I will!memberNaerling24 Feb '12 - 22:32 
how search record in c#[^]
Read the first few sentences of my answer. Yes, I thought of you Wink | ;)
It's an OO world.
public class Naerling : Lazy<Person>{
    public void DoWork(){ throw new NotImplementedException(); }
}

GeneralMy vote of 4memberKlaus Luedenscheidt4 Feb '12 - 18:48 
i revise my former vote. Good work to put all infos together
GeneralMy vote of 5member|T|oniyo |J|ackson4 Feb '12 - 6:39 
Useful article.
GeneralMy vote of 5mvp_ Kunal Chowdhury _4 Feb '12 - 2:38 
Great Job. Finally, I can see it now Wink | ;)
GeneralMy Vote of 5mvpRaviRanjankr1 Feb '12 - 4:07 
Nice blog with good collection of links Thumbs Up | :thumbsup:
GeneralMy vote of 5mentorBrij30 Jan '12 - 4:24 
Excellent post!! Keep it up
GeneralGood reference article.memberWonde Tadesse29 Jan '12 - 14:08 
Keep it up for the good work and have 5. Thumbs Up | :thumbsup:
Wonde Tadesse
MCTS

QuestionWhole lotta conversions!memberNaerling29 Jan '12 - 9:49 
Interesting blog. Never knew there was so much conversing going on Wink | ;)
I'll be sure to reference this next time someone in QA (or anywhere) needs it.
I use DeveloperFusion most of the time btw. I sometimes need to translate some C# examples to VB and converting is easier (and quicker) than to rewrite Smile | :)
 
And my vote of 5 of course! (I was somehow under the impression that that would've been added to the subject line if I selected it in the 'new message' window).
It's an OO world.
public class Naerling : Lazy<Person>{
    public void DoWork(){ throw new NotImplementedException(); }
}

GeneralMy vote of 5mvpSAKryukov29 Jan '12 - 7:29 
Good reference material to answer questions of the Questions & Answers users, which you successfully do.
 
Cheers,
—SA

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130523.1 | Last Updated 4 Feb 2012
Article Copyright 2012 by thatraja
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid