powered by UserVoice

Code Converter Forum

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***

  1. 52 votes

    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 +… more

  2. 19 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 Get

    Set(ByVal value As String)
    ViewState("SortColumn")… more

    Status: under review

    Unfortunately 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?

  3. 16 votes

    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;

  4. 15 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… more

  5. 15 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

  6. 11 votes

    Delegates

    If button.InvokeRequired Then
    Dim o As Object = scriptableButton.Invoke(New System.Windows.Forms.MethodInvoker(UserInterfaceCode))
    End If

    Should be

    If button.InvokeRequired Then
    Dim o As Object = scriptableButton.Invoke(New System.Windows.Forms.MethodInvoker(addressof UserInterfaceCode))
    End If

  7. 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}

  8. 9 votes

    trim

    The syntax in VB is

    returnValue = inputValue.Trim

    When converting to C# it is not adding the "()" to the end of "Trim"

    Status: under review
  9. 7 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

  10. 7 votes

    Implement conversion for yield statement into VB.NET

    Using an IEnumerable collection and returning that instead

  11. 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 =… more

  12. 6 votes

    optional method parameters not converted from VB to C#

    Methods with Optional Parameters,
    Private Sub ThisMethod(Optional byRef strVal as String = "me")

    Are not converted . creating overloaded methods might be a way to go, just add into the base method the additional variables assigned with default values.
    see below example.
    //method assigns argument to default inside the class … more

  13. 6 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(" ")
    Next

    Which comes up invalid

  14. 6 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 = 0

  15. 6 votes

    C# to Ruby or Python

    The following converts to VB.net but not ruby or python:
    for(int i = 0; i<1; i++){
    Console.Write("i: "+i);
    }

    Status: under review

    Pat - if you place a class and method definition around the C# code, it will then convert to Ruby/Python :) We're looking at getting this fixed

  16. 6 votes

    Add Intelligence to code conversion to weed out common errors and peculiarities

    There are multiple special cases where hard logic cant decide which way to go. e.g:

    1. Array variables, Known properties like ViewState, Session etc
    Current: Request.QueryString("key") -> Request.QueryString("key");
    Correct: Request.QueryString("key") -> Request.QueryString["key"];

    2. Optional brackets in VB methods are not so optional in C#
    Current: myvar.ToString -> mycar.ToString;
    Correct: myvar.ToString… more

  17. 5 votes

    C#.NET to python

    I am not able to convert C# code to Python..

  18. 5 votes
  19. 5 votes

    #if...#else...#endif

    When converting such a block from C# to VB.NET the #else-Line jumps outside the block:

    class Foo {
    void Bar() {
    #if DEBUG
    DoSomehting();
    #else
    DoSomethingElse();
    #endif
    }
    }

    Class Foo
    Private Sub Bar()
    #If DEBUG Then
    DoSomehting()
    #Else
    #End If
    DoSomethingElse()
    End Sub
    End Class

  20. 5 votes

    Missing Parentheses Are Not Added In VB to C# Conversion

    In VB, parameter-less class methods that are used in assignment declarations do not require parentheses. However, in C#, these functions must have parentheses or they generate a compiler error.

    For example, take the following VB code:

    Private Sub DisplayString()
    MessageBox.Show(Me.ReturnString)
    End Sub

    Private Function ReturnString() As String
    Return "test"
    End… more

powered by UserVoice