Results 1 to 7 of 7

Thread: C# and VB

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2005
    Posts
    258

    C# and VB

    Which is faster? I know C++ is the fastest but I know C# is basically a managed C++. Correct me if I'm wrong because C# is a language I am becomming more interested everyday. Is C# faster performancewise or is it basically just another way to write code?


    Thanks to all who reply!

    Taco

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: C# and VB

    C# is not a managed C++. C++.NET is managed C++. C# is no more managed C++ than Java is. They are both languages that are based on C/C++ syntax but they are both quite different as well. Generally speaking, a VB.NET app that does the same thing as a C# app will perform exactly the same. They both get compiled to MSIL, and often exactly the same MSIL. C# provides some features that make it easier to write code that will perform faster, like the use of pointers in unsafe code blocks, but in general usage most developers won't use them anyway. I've written a fair bit of C# code and never used a pointer. The language was designed in such a way that you normally don't need to. You can speed up certain operations considerably by their use, but the same issues exist with pointers in C# as do in C++, which is why they are a bonus in certain situations but it's probably preferable to avoid them in general.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Hyperactive Member umilmi81's Avatar
    Join Date
    Sep 2005
    Location
    Sterling Heights, Mi.
    Posts
    335

    Re: C# and VB

    Good post.

    I'd also like to point out a thing I read. C# and VB.NET have the opportunity to be absolutely identical in speed.

    However, in practice C# will get a very very tiny edge. The reason is because of the verboseness of the VB.NET language. The structures are broken out to multiple statements internally.

    Example:
    VB.NET
    VB Code:
    1. For i as Integer = 0 to 10
    2.   'Some code
    3. Next
    When the above is compiled into MSIL it is actually expanded to:
    Code:
    int i;
    i=0;
    while(i <= 10)
    {
      'some code
      i++;
    }
    Meanwhile, in C#
    Code:
    for(int i = 0 ; 0<=10 ; i++)
    {
      //some code
    }
    The above statement is translated more cleanly and efficiently because there is no need to translate the word like structure into IL.

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: C# and VB

    Here are some differences
    http://thecodeproject.com/dotnet/vbvscsmsil.asp

    Bear in mind that even different IL usually gets compiled to the same native code by the JIT compiler.

  5. #5
    Frenzied Member Phill64's Avatar
    Join Date
    Jul 2005
    Location
    Queensland, Australia
    Posts
    1,201

    Re: C# and VB

    If you were to use the VisualBasic namespace your application would probably compile to slower code than a C# version, but of course if you do everything the global .NET way that's not a problem.

    Pointers aside Unsigned Ints are available in C# which makes a difference in large for loops, however i think they allowed the use of UInts in VB.NET 2005?

    In my opinion alot of it comes down to the way you code, if you do it scrappy in C# it is still going to be worse than if it was done properly in VB.NET

    Personally I like writing my applications in both, front-end VB.NET and DLLs in C# for large operations. I find basic syntax suits form manipulation, and the c format suits data manipulation.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: C# and VB

    Quote Originally Posted by Phill64
    Personally I like writing my applications in both, front-end VB.NET and DLLs in C# for large operations. I find basic syntax suits form manipulation, and the c format suits data manipulation.
    One of the nice things about .NET and Visual Studio is that you have the freedom to make that choice. Applications and libraries written in different languages have always been able to interact, but it's never been as easy and well integrated as it is in recent VS releases.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7
    New Member
    Join Date
    Dec 2005
    Location
    United States
    Posts
    7

    Re: C# and VB

    As far as .Net goes you may want to take a look at the book I included at the bottom of this post. I realize your question is reguarding C++ vs. C#, however, I still think this book might come in handy because it describes the .Net Framework in some detail.

    As a general rule Microsoft claims in several articles and in this book that all .Net languages are supposed to execute at the same speed because they are all compiled to the same MSIL. But I'm sure there are differences here and there that may make one language a little faster then another. It all depends on the code you need to write.

    I think the point here is to choose the language you are the most fimiliar with. Don't choose C++ just because it may be the fastest language compaired to C#. C++ may be faster but if your code is written like crap, then it may actually end up being a lot slower then C#.

    Choose the language that makes you more productive.

    I'm not sure how much this book will help in your case, but its worth taking a look at. If you can get it from your local library for free.

    MCAD/MCSD
    Developing Windows-Based Applications
    Microsoft Press
    ISBN: 0-7356-1926-3
    - Billiard
    If you would like me to read your code, please use [code] tags.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width