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*

These don't convert correctly for...

You've used all your votes and won't be able to post a new idea, but you can still search and comment on existing ideas.

There are two ways to get more votes:

  • When an admin closes an idea you've voted on, you'll get your votes back from that idea.
  • You can remove your votes from an open idea you support.
  • To see ideas you have already voted on, select the "My feedback" filter and select "My open ideas".
(thinking…)

Enter your idea and we'll search to see if someone has already suggested it.

If a similar idea already exists, you can vote and comment on it.

If it doesn't exist, you can post your idea so others can vote on it.

Enter your idea and we'll search to see if someone has already suggested it.

  1. 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
    Vote
    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      You have left! (?) (thinking…)
      2 comments  ·  Flag idea as inappropriate…  ·  Admin →
    • 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
      Vote
      Sign in
      Check!
      (thinking…)
      Reset
      or sign in with
      • facebook
      • google
        Password icon
        I agree to the terms of service
        Signed in as (Sign out)
        You have left! (?) (thinking…)
        0 comments  ·  Flag idea as inappropriate…  ·  Admin →
      • Implement conversion for yield statement into VB.NET

        Using an IEnumerable collection and returning that instead

        26 votes
        Vote
        Sign in
        Check!
        (thinking…)
        Reset
        or sign in with
        • facebook
        • google
          Password icon
          I agree to the terms of service
          Signed in as (Sign out)
          You have left! (?) (thinking…)
          1 comment  ·  Flag idea as inappropriate…  ·  Admin →
        • 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") = value
          End Set

          End Property

          Private Sub Test

          ParentControlID = Request.Params("ParentCtlID")

          If DirectCast(Session("USER_TOKEN"), Int32) > 0 Then
          UserCanEditAddBook = True
          End If

          End Sub

          20 votes
          Vote
          Sign in
          Check!
          (thinking…)
          Reset
          or sign in with
          • facebook
          • google
            Password icon
            I agree to the terms of service
            Signed in as (Sign out)
            You have left! (?) (thinking…)
            2 comments  ·  Flag idea as inappropriate…  ·  Admin →

            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?

          • 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
            Vote
            Sign in
            Check!
            (thinking…)
            Reset
            or sign in with
            • facebook
            • google
              Password icon
              I agree to the terms of service
              Signed in as (Sign out)
              You have left! (?) (thinking…)
              1 comment  ·  Flag idea as inappropriate…  ·  Admin →
            • 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
              Vote
              Sign in
              Check!
              (thinking…)
              Reset
              or sign in with
              • facebook
              • google
                Password icon
                I agree to the terms of service
                Signed in as (Sign out)
                You have left! (?) (thinking…)
                0 comments  ·  Flag idea as inappropriate…  ·  Admin →
              • Code converter is broken.

                Trying to use code converter gives "processing" without results, no matter how much you wait.

                15 votes
                Vote
                Sign in
                Check!
                (thinking…)
                Reset
                or sign in with
                • facebook
                • google
                  Password icon
                  I agree to the terms of service
                  Signed in as (Sign out)
                  You have left! (?) (thinking…)
                  1 comment  ·  Flag idea as inappropriate…  ·  Admin →
                • 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
                  Vote
                  Sign in
                  Check!
                  (thinking…)
                  Reset
                  or sign in with
                  • facebook
                  • google
                    Password icon
                    I agree to the terms of service
                    Signed in as (Sign out)
                    You have left! (?) (thinking…)
                    under review  ·  3 comments  ·  Flag idea as inappropriate…  ·  Admin →
                  • 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

                    12 votes
                    Vote
                    Sign in
                    Check!
                    (thinking…)
                    Reset
                    or sign in with
                    • facebook
                    • google
                      Password icon
                      I agree to the terms of service
                      Signed in as (Sign out)
                      You have left! (?) (thinking…)
                      0 comments  ·  Flag idea as inappropriate…  ·  Admin →
                    • 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

                      11 votes
                      Vote
                      Sign in
                      Check!
                      (thinking…)
                      Reset
                      or sign in with
                      • facebook
                      • google
                        Password icon
                        I agree to the terms of service
                        Signed in as (Sign out)
                        You have left! (?) (thinking…)
                        0 comments  ·  Flag idea as inappropriate…  ·  Admin →
                      • 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
                        Vote
                        Sign in
                        Check!
                        (thinking…)
                        Reset
                        or sign in with
                        • facebook
                        • google
                          Password icon
                          I agree to the terms of service
                          Signed in as (Sign out)
                          You have left! (?) (thinking…)
                          0 comments  ·  Flag idea as inappropriate…  ·  Admin →
                        • 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
                          Vote
                          Sign in
                          Check!
                          (thinking…)
                          Reset
                          or sign in with
                          • facebook
                          • google
                            Password icon
                            I agree to the terms of service
                            Signed in as (Sign out)
                            You have left! (?) (thinking…)
                            0 comments  ·  Flag idea as inappropriate…  ·  Admin →
                          • 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
                            Vote
                            Sign in
                            Check!
                            (thinking…)
                            Reset
                            or sign in with
                            • facebook
                            • google
                              Password icon
                              I agree to the terms of service
                              Signed in as (Sign out)
                              You have left! (?) (thinking…)
                              1 comment  ·  Flag idea as inappropriate…  ·  Admin →
                            • 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
                              Vote
                              Sign in
                              Check!
                              (thinking…)
                              Reset
                              or sign in with
                              • facebook
                              • google
                                Password icon
                                I agree to the terms of service
                                Signed in as (Sign out)
                                You have left! (?) (thinking…)
                                0 comments  ·  Flag idea as inappropriate…  ·  Admin →
                              • 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

                                9 votes
                                Vote
                                Sign in
                                Check!
                                (thinking…)
                                Reset
                                or sign in with
                                • facebook
                                • google
                                  Password icon
                                  I agree to the terms of service
                                  Signed in as (Sign out)
                                  You have left! (?) (thinking…)
                                  1 comment  ·  Flag idea as inappropriate…  ·  Admin →
                                • 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
                                  Vote
                                  Sign in
                                  Check!
                                  (thinking…)
                                  Reset
                                  or sign in with
                                  • facebook
                                  • google
                                    Password icon
                                    I agree to the terms of service
                                    Signed in as (Sign out)
                                    You have left! (?) (thinking…)
                                    1 comment  ·  Flag idea as inappropriate…  ·  Admin →
                                  • C#.NET to python

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

                                    8 votes
                                    Vote
                                    Sign in
                                    Check!
                                    (thinking…)
                                    Reset
                                    or sign in with
                                    • facebook
                                    • google
                                      Password icon
                                      I agree to the terms of service
                                      Signed in as (Sign out)
                                      You have left! (?) (thinking…)
                                      2 comments  ·  Flag idea as inappropriate…  ·  Admin →
                                    • -- 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
                                      Vote
                                      Sign in
                                      Check!
                                      (thinking…)
                                      Reset
                                      or sign in with
                                      • facebook
                                      • google
                                        Password icon
                                        I agree to the terms of service
                                        Signed in as (Sign out)
                                        You have left! (?) (thinking…)
                                        1 comment  ·  Flag idea as inappropriate…  ·  Admin →
                                      • 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
                                        Vote
                                        Sign in
                                        Check!
                                        (thinking…)
                                        Reset
                                        or sign in with
                                        • facebook
                                        • google
                                          Password icon
                                          I agree to the terms of service
                                          Signed in as (Sign out)
                                          You have left! (?) (thinking…)
                                          1 comment  ·  Flag idea as inappropriate…  ·  Admin →
                                        • 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
                                          Vote
                                          Sign in
                                          Check!
                                          (thinking…)
                                          Reset
                                          or sign in with
                                          • facebook
                                          • google
                                            Password icon
                                            I agree to the terms of service
                                            Signed in as (Sign out)
                                            You have left! (?) (thinking…)
                                            1 comment  ·  Flag idea as inappropriate…  ·  Admin →
                                          ← Previous 1 3 4 5 6 7 8 9 10 11 12 13 14
                                          • Don't see your idea?

                                          Code Converter

                                          Feedback and Knowledge Base