Code Converter
Welcome to our official feedback forum for the code converter. If you spot problems with the converter, just leave a note here. Please make sure you include a code sample*
-
Array brackets
VB.NET Array parentheses do not translate to C# brackets
Example (VB.NET):
Dim pts(2) As Point
pts(0) = New Point(left + arrowWidth / 2 - 2 -extra - 2, top + height / 2 - 1)
pts(1) = New Point(left + arrowWidth / 2 + 3 +extra - 1, top + height / 2 - 1)
pts(2) = New Point(left + arrowWidth / 2 - 1,(top + height / 2 - 1) + 3 + extra)Translates to (C#):
Point[] pts = new Point[3];
pts(0) = new Point(left + arrowWidth / 2 - 2 - extra - 2, top + height…66 votes -
AddHandler
Please use AddHandler statements when converting C# event handlers to VB text...
For example, instead of converting a C# handler to this...
queue.QueueItemAvailable += Me.ContinueAt
do this...
AddHandler queue.QueueItemAvailable, Addressof Me.ContinueAt
32 votes -
Implement conversion for yield statement into VB.NET
Using an IEnumerable collection and returning that instead
26 votes -
ViewState, Session or Request.Params not arrays
In my example below, none of the ViewState, Session or Request Params (arrays) have their round brackets converted to square brackets.
Example:
Protected Property CurrentSortColumn() As String
Get
If (ViewState("SortColumn") <> Nothing) Then
Return ViewState("SortColumn").ToString()
Else
ViewState("SortColumn") = "ADD_BOOK_ID"
Return "ADD_BOOK_ID"
End If
End GetSet(ByVal value As String)
ViewState("SortColumn") = value
End SetEnd Property
Private Sub Test
ParentControlID = Request.Params("ParentCtlID")
If DirectCast(Session("USER_TOKEN"), Int32) > 0 Then
UserCanEditAddBook = True
End IfEnd Sub
20 votesUnfortunately we have no reliable way of knowing for sure that ViewState is an array rather than a method. We could guess for certain variable names (ViewState, Request etc) but this could confuse the issue further were these to conflict with actual methods… what do people think?
-
Suggest code to make event handlers work (VB.Net -> C#)
The converter could suggest the code needed to bind an event handler.
Example:
Private Sub SomeObject_SomeEvent(Arguments as Object) Handles SomeObject.SomeEvent
The following code could be suggested (in a comment):
SomeObject.SomeEvent += SomeObject_SomeEvent;19 votes -
Array Problem with StringDictionary
I had a bit of an issue with a StringDictionary collection when converting.
Original Code: (VB)
sServiceName = Me.Context.Parameters.Item("name")
sServiceDescription = Me.Context.Parameters.Item("description")
sServiceDisplayName = Me.Context.Parameters.Item("displayname")Converted Code: (C#)
sServiceName = this.Context.Parameters.Item("name");
sServiceDescription = this.Context.Parameters.Item("description");
sServiceDisplayName = this.Context.Parameters.Item("displayname");Correct Code: (C#)
sServiceName = this.Context.Parameters["name"];
sServiceDescription = this.Context.Parameters["description"];
sServiceDisplayName = this.Context.Parameters["displayname"];In C#, Array.Item(key) is not valid. It should be Array[key].
15 votes -
Code converter is broken.
Trying to use code converter gives "processing" without results, no matter how much you wait.
15 votes -
trim
The syntax in VB is
returnValue = inputValue.Trim
When converting to C# it is not adding the "()" to the end of "Trim"
14 votes -
Delegates
If button.InvokeRequired Then
Dim o As Object = scriptableButton.Invoke(New System.Windows.Forms.MethodInvoker(UserInterfaceCode))
End IfShould be
If button.InvokeRequired Then
Dim o As Object = scriptableButton.Invoke(New System.Windows.Forms.MethodInvoker(addressof UserInterfaceCode))
End If12 votes -
Puts 'As var' improperly into converted code
foreach (var w in res1) Console.WriteLine(" ");
Converts incorrectly to VB as:
For Each w As var In res1
Console.WriteLine(" ")
NextWhich comes up invalid
11 votes -
Missing 'With' Object Initializers
In C#:
StringFormat sfCenter = new StringFormat() {Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center };Converted to VB.NET:
sfCenter As New StringFormat()Expected result:
sfCenter As New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center}11 votes -
Cannont convert Nullable property using ?
When trying to convert from VB.Net to C# (or vice versa), if you have a nullable property that is created using the ? and not Nullable<> the post back on your page is not ready correctly.
Public Property CurrentDate As DateTime?
I should be able to pass that and get
public DateTime? CurrentDate { get; set; }
10 votes -
initailized object
c# code
var textBox = new RibbonTextBox() { Label = "Label", Text = "Text", TextBoxWidth = 150 };
incorrectly converted to vb.net as
Dim textBox = New RibbonTextBox() With { _
Key .Label = "Label", _
Key .Text = "Text", _
Key .TextBoxWidth = 150 _
}where "Key" is not needed, should be:
Dim textBox = New RibbonTextBox() With {.Label = "Label", .Text = "Text", .TextBoxWidth = 150}
10 votes -
Joining strings
Just realised (and also learned) that there's a small error when converting VB's Strings.Join into C# code.
The VB code:Dim message As String = Join(anArrayList.ToArray, ",");
converts in C# to:
string message = Strings.Join(anArrayList.ToArray(), ",");
where it should be:
string message = String.Join(",", anArrayList.ToArray());
9 votes -
VB's floating-point division operator is converted to C#'s integer division.
'VB
Dim a As New TimeSpan(1000L)
Dim b As New TimeSpan(2000L)
Dim d As Double = a.Ticks / b.Ticks 'd = 0.5//Converted to C#
TimeSpan a = new TimeSpan(1000L);
TimeSpan b = new TimeSpan(2000L);
double d = a.Ticks / b.Ticks 'd = 09 votes -
i++; fails
When converting the following from C# to VB.NET it fails to convert correctly.
int i=5;
int j=i++;
//i=6 and j=5
It sets Dim j = System.Math.Max(System.Threading.Interlocked.Increment(i),i-1)Not possible for i-1 to be greater than i+1
8 votes -
C#.NET to python
I am not able to convert C# code to Python..
8 votes -
-- line 1 col 1: EOF expected
I have c# code:
<%: Html.DropDownList("ArtistId", new SelectList(ViewData["Artists"] as IEnumerable, "ArtistId", "Name", Model.ArtistId))%>many asp.net mvc c# code can not convert to vb
7 votes -
Submitting code to be converted via URL
Is there a way to post code to be converted via a URL instead of the site's web form? I can easily create a javascript bookmarklet in my browser to accept my code to be converted (via clipboard or current selection), so it would be nice to be able to submit that to the conversion site via a URL without having to first open a new browser window to the conversion site's web form. Great tool--use it frequently!
6 votes -
Linq Query from C# to VB
Here's an example from Microsoft's Tailspin Spyworks tutorials that translates very poorly.
============
var query = (from ProductOrders in db.OrderDetails
join SelectedProducts in db.Products on ProductOrders.ProductID equals SelectedProducts.ProductID
group ProductOrders by new
{
ProductId = SelectedProducts.ProductID,
ModelName = SelectedProducts.ModelName} into grp
select new
{
ModelName = grp.Key.ModelName,
ProductId = grp.Key.ProductId,
Quantity = grp.Sum(o => o.Quantity)
} into orderdgrp
where orderdgrp.Quantity > 0
orderby orderdgrp.Quantity descending
select orderdgrp).Take(5);========
If you run the convertor on this, you'll find several statements that merge together, "select" disappears entirely and whatever was on either side of it merges into a single word, "equals"…6 votes
- Don't see your idea?