Evaluating VB.NET to C# converters
I am converting several projects from VB.NET to C#. In preparation for this, I tested 4 different VB.NET to C# conversion tools with sample code from those projects.
I encountered several problems, and I thought that I'd share my findings with others who might be going through the same process (I initially paid for the wrong tool by mistake).
Converting the following tiny VB.NET application with each of the tools demonstrates some of the problems that I ran into:
Telerik Code Converter
Free online tool: https://converter.telerik.com (tested on Dec 30th, 2023)
On the first attempt, this converter "crashes" (included a long error message in the output) because of the date literal #1970-01-02#
in line 6 of the VB code.
After changing the date literal in the VB code to New DateTime(1970,1,2)
, I get this output:
The only remaining issue is in line 11 of the output - the VB ternary operator if(...,...,...)
was correctly converted to C# ...?...:...
- but missing surrounding parentheses. This could lead to some nasty bugs...
After adding the missing parentheses, this C# code compiled and ran.
ICSharpCode Converter
Free online tool: https://icsharpcode.github.io/CodeConverter (tested on Dec 30th, 2023)
Also available as a Visual Studio extension: Code Converter (VB - C#)
Output:
Notice lines 10-12 (corresponding to lines 6-8 of the VB code). The code for those lines is just gone! This appears to have something to do with the lambda function as it does not happen in regular functions.
The same thing happens in the Visual Studio extension.
VBConversions
Windows desktop application from https://vbconversions.com
Testing with version 5.08 (paid $295 for "Lifetime License") using the "Snippet converter" function.
Output:
This converter also appears to have a problem with lambda functions (output lines 8/9).
Also, any variable declaration with an initializer of an inferred type (Dim VariableName =...
) is converted to object VariableName =...
(output line 13). The other converters output var VariableName= ...
which works a lot better.
Also, the VB ternary operator if(...,...,...)
was not converted at all (output line 14).
Also, it does not handle VB multi-line statements correctly (output lines 14-15).
Instant C# .
Windows desktop application from https://www.tangiblesoftwaresolutions.com/product_details/vb-to-csharp-converter.html
Testing with version 23.12.21 (paid $159 for a "One-Year Subscription License") using the"Code Snippets" function.
Output:
Compiled and ran correctly on the first attempt.
Conclusion
Looks like I will be using Instant C#