SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

Optimization: Convert C# to VB.NET

Last post 04-02-2008 4:46 AM by DanielGrunwald. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 11-13-2007 12:38 PM

    • Ewald
    • Not Ranked
    • Joined on 11-13-2007
    • Posts 2

    Optimization: Convert C# to VB.NET

    The following C# code 

       String Test = "My Test\n" ;

    converts to VB.NET

       Dim Test As String = "My Test" & Chr(10) & "" 

    and back to C#

       string Test = "My Test" + Strings.Chr(10) + ""; 

    I think the code could be optimized by replacing escape sequences in the converted VB.NET code with their constants like vbLF, vbNewline etc. and vice versa.

    Also the empty string can be either removed completely or replaced with the faster String.Empty.


    Filed under:
  • 11-13-2007 1:15 PM In reply to

    Re: Optimization: Convert C# to VB.NET

    string.Empty is not faster than "", if you look at the generated native code you'll see that both compile to a single MOV instruction. There are a lot of myths about the performance of string operations in .NET that are simply not true (especially common myth: "StringBuilder is faster than +").

    The converter should not create any empty string literals; and you're right that constants should be preferred when they exist (are there constants for \0, \v, \b, \f, \a ?)

    Daniel Grunwald
  • 11-13-2007 1:39 PM In reply to

    • Ewald
    • Not Ranked
    • Joined on 11-13-2007
    • Posts 2

    Re: Optimization: Convert C# to VB.NET

    You're certainly right with the string performance. I 'converted' that knowledge from VB6, got used to replace "" with vbNullString etc. and have not checked again with .NET.

    I knew of constants for Chr(8) up to Chr(13) and some combinations. Chr(0) is vbNullChar.

     

    Filed under:
  • 04-02-2008 4:46 AM In reply to

    Re: Optimization: Convert C# to VB.NET

     Implemented in revision 3022.

    Daniel Grunwald
Page 1 of 1 (4 items)
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.