Is it possible to convert code from Java to C# or VB.net to C#?
You could decompile the VB.NET code using Reflector (http://www.red-gate.com/products/reflector/) to get it as C#. You might also try someting like this online converter http://www.developerfusion.com/tools/convert/vb-to-csharp/
Try Telerik Code Converter for a free C#/VB code converter. I've used it - it isn't bad. There are also many commercial ones with lots of features.
Java and C# are very similar and converting between the two (and to/from VB) is possible. A quick search should reveal many commercial options.
If you know a little bit of both C# and Java, converting Java to C# by hand would be the best route to go. That's what I did for a relativley medium sized Java project. Then you can use Sharpdevelop (http://www.icsharpcode.net/opensource/sd/) to convert C# to VB and vice versa.
For Java to C# &VB.Net, you can also use Tangible Java to VB & C# Converter.
http://tangiblesoftwaresolutions.com
I hope this could be useful. But it might not work with complex code structures..
https://varycode.com/converter.html
Related
Is there an online resource or database that allows looking up the C# equivalent to a Java class and vice versa?
I have been porting code and have been Googling individual classes one at a time; it gets a little tedious. 8^j
Cheers
something as simple as this: http://www.harding.edu/fmccown/java_csharp_comparison.html
or more about the libraries available on each?
1 * Google "C# api" = http://msdn.microsoft.com/en-us/library/d11h6832(v=vs.71).aspx
Rosetta Code is a nice approach, though it is more comprehensive than you're after. The goal of the site is to show the same task being done in as many languages as possible. For example, for File IO, you could search for the Java and C# versions and compare them.
I am looking to switch to C#. I come from a C / C++ background but C# is a little different for me. I am switching mainly because of Silverlight and MVVM; all examples are in C#. Any information is in C# and I am confused when I read through it all.
What is a good place to start learning C# when starting with existing C / C++ knowledge?
Start writing code in C# ASAP. Only way to learn the language is to write it. You already understand VB.NET. You've got a huge lead on anyone new to .NET.
Take a smallish application you've written in VB.NET and methodically change it over to C#.
You'll learn the syntax, etc. quickly.
Write all of your future projects in C#. Just force yourself into the change and you'll do fine.
Read the best C# books. :)
The Wikipedia article "C Sharp (programming language)" is a decent introduction to C# as a language.
Shortly after learning VB.NET I decided I'd rather be coding C#. I learned it by reading a couple of books and working on a project. Slowly, I got my coworkers converted over to the language from VB.NET as well. The languages are very similar, some code conversion is just a matter of changing syntax.
However, if you've ever worked with a true VB'er you will see VB specific functions used in their code that'll make you scratch your head. There are string handling functions and casting functions for example that you will have to convert. Also, C# has no RaiseEvent. Events take a little more effort to understand in C# because you need to wrap your mind around delegates (C++ function pointers/callbacks). As others have said, if you are coming from C++ this shouldn't be too difficult.
Many people go on about needing to work on a project to understand a language, which I agree with. However, there are features of languages which you will never know about if you don't pick up a couple of books and read about them. I've been able to show my coworkers many useful techniques just by reading a couple of books.
Lastly, C# is a great language. I was very skeptical when I first started using .NET, but now I know that MS got the right talent together for that framework and language.
Good luck.
As you know C++ (as you wrote in the question) and VB.Net (as you mentioned in the title), C# won't be hard for you if do know them both well. If this is the case, just grab any source in C#, and read it.
By the way, the article from wikipedia is a very nice intro.
One thing that may work for you is to use a converter
Write your desired code in VB.
Paste small pieces of code you don't know how to write in C# into http://converter.telerik.com/ and convert.
Manually type the result into your C# project.
Gradually, reduce your reliance on converter as you become more familiar with language.
That is enough to get you started, however C# has language features that VB does not, or VB offers in a way that is so wordy that no one really uses it.
The more features you will come across as you look at code examples from around the web (like on stack overflow), and you need to either look up syntax or function manually, or convert from C# back to vb to understand what it is doing (use same converter). Or, just paste it in and see what it does.
I am working on a SQl Server Report Services project and the report I am creating requires some custom code. It seems that all expressions must be in VB.NET and I figured if there was an 'easy' way to switch that over to be C#, it would be helpful.
EDIT:
Well, I decided to move my code to another C# assembly that follows the patterns like this example.
It's VBA (Visual Basic for Applications) rather than VB.NET, so it's not .NET, it's an embedded scripting language. Therefore I would expect that there's no way to switch to C#.
I believe that the reports are using something more along the lines of VBScript (Edit: OregonGhost says VBA which actually makes more sense than VBScript) than VB.NET (and very limited at that). I have not seen any way of switching it over to C#, and I would like to be proven wrong.
The short answer is no. And the language as described my MSDN is not really VB.NET, but Visual Basic
I know CodeGear made BabelCode that uses the Code DOM to convert C# to Delphi for .NET. I am curious if there are any other similar tools to convert C# to Delphi Prism? If not, what is involved in using the Code DOM to create one (yeah, that is open ended!)
Update: This is now built into Delphi Prism. Just paste or import your C# and you have Oxygene aka Delphi Prism Code.
It's in its early stages but Carlo just published a first revision of his open source "C# to Oxygene" tool:
http://code.remobjects.com/p/csharptoxy/
One option I saw was to use .NET Reflector on the C# compiled assembly. It has an Oxygene syntax. That is kind of the long way around and not exactly optimal.
Use BabelCode to convert your C# to Delphi, and then use Oxidizer to convert Delphi to Prism. Not a stellar idea, I realize, but it might at least be a little more automatable than going through Reflector. Good luck.
I have a small (~2000 lines of code) class that I would like to use from both java & .NET. There are several approaches to do this - among them wrapping the class as a service, using some interop voodoo, or duplicating the code to both C# & java.
Do you know an out-of-the-box tool that accomplishes the latter - takes a simple C# class with no dependencies and converts it to an equivalent java class?
IKVM.NET does pretty good job in taking a jar file and compiling it to a managed .NET assembly.
If it is small (or in fact, even if it is large), I'm not sure of the wisdom of mechanical translation tools; I've simply never had much joy with them. However, one option would be to write the .NET code in J#.
But I stress - if it was me, I'd manually port it between the two manually and maintain them separately. Most of the time the differences aren't huge - signed bytes, the boxing differences, etc. Of course, anything with delegates will need changing - and captured variables work differently, etc etc.
There used to be a COM bridge and you can register C# assemblies for use in COM with regasm.exe or visual studio.
It's not really what you asked for, but I would just create a simple C# to Java translator.
The differences are not that huge and you seem to be the author of the source so you can avoid nasty constructs that are quite difficult to translate. That way your translator would be quite simple. I would go from C# to Java because C# is more expressive, and you can emulate almost all the C# functions in Java.
Actually cs2java seems to do just that.
This is list of tools I know. Sharpen or j2cstranslator looks like good options.