Evaluating VB.NET to C# converters
Tags: vb, vbnet, visualbasic, csharp
Published: 2024-01-02 11:03:00

---
title: Evaluating VB.NET to C# converters
published: true
description: 
tags: ["vb","vbnet","visualbasic","csharp"]
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c4wl78sgykm5x51ucmmo.png
published_at: 2024-01-02 11:03 +0000
canonical_url: https://jesperhoy.dev/evaluating-vb-net-to-c-sharp-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:

![vb.net code](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v39ahcnhae51ft0v7gay.png)

## Telerik Code Converter

Free online tool: [https://converter.telerik.com](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:

![c# code](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v4n1k30oogebw1ydaq3r.png)

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](https://icsharpcode.github.io/CodeConverter) (tested on Dec 30th, 2023)  
Also available as a Visual Studio extension: [Code Converter (VB - C#)](https://marketplace.visualstudio.com/items?itemName=SharpDevelopTeam.CodeConverter&ssr=false#overview)

Output:

![c# code](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x2jxndsdwywp9bndhyui.png)

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](https://vbconversions.com)  
Testing with version 5.08 (paid $295 for "Lifetime License") using the "Snippet converter" function.

Output:

![c# code](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6id22w9y2ptki1q2po3b.png)

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](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:

![c# code](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nk8scuoxpfmu3agw12lj.png)

Compiled and ran correctly on the first attempt.

## Conclusion

Looks like I will be using Instant C#