What are the advantages of C# over VB.NET and vice versa?

What are the advantages of C# over VB.NET and vice versa?

Rate This
  • Comments 42

The choice between C# and VB.NET is largely one of subjective preference. Some people like C#'s terse syntax, others like VB.NET's natural language, case-insensitive approach. Both have access to the same framework libraries. Both will perform largely equivalently (with a few small differences which are unlikely to affect most people, assuming VB.NET is used with Option Strict on). Learning the .NET framework itself is a much bigger issue than learning either of the languages, and it's perfectly possible to become fluent in both - so don't worry too much about which to plump for. There are, however, a few actual differences which may affect your decision:

VB.NET Advantages
  • Support for optional parameters - very handy for some COM interoperability
  • Support for late binding with Option Strict off - type safety at compile time goes out of the window, but legacy libraries which don't have strongly typed interfaces become easier to use.
  • Support for named indexers (aka properties with parameters).
  • Various legacy VB functions (provided in the Microsoft.VisualBasic namespace, and can be used by other languages with a reference to the Microsoft.VisualBasic.dll). Many of these can be harmful to performance if used unwisely, however, and many people believe they should be avoided for the most part.
  • The with construct: it's a matter of debate as to whether this is an advantage or not, but it's certainly a difference.
  • Simpler (in expression - perhaps more complicated in understanding) event handling, where a method can declare that it handles an event, rather than the handler having to be set up in code.
  • The ability to implement interfaces with methods of different names. (Arguably this makes it harder to find the implementation of an interface, however.)
  • Catch ... When ... clauses, which allow exceptions to be filtered based on runtime expressions rather than just by type.
  • The VB.NET part of Visual Studio .NET compiles your code in the background. While this is considered an advantage for small projects, people creating very large projects have found that the IDE slows down considerably as the project gets larger.
C# Advantages
  • XML documentation generated from source code comments. (This is coming in VB.NET with Whidbey (the code name for the next version of Visual Studio and .NET), and there are tools which will do it with existing VB.NET code already.)
  • Operator overloading - again, coming to VB.NET in Whidbey.
  • Language support for unsigned types (you can use them from VB.NET, but they aren't in the language itself). Again, support for these is coming to VB.NET in Whidbey.
  • The using statement, which makes unmanaged resource disposal simple.
  • Explicit interface implementation, where an interface which is already implemented in a base class can be reimplemented separately in a derived class. Arguably this makes the class harder to understand, in the same way that member hiding normally does.
  • Unsafe code. This allows pointer arithmetic etc, and can improve performance in some situations. However, it is not to be used lightly, as a lot of the normal safety of C# is lost (as the name implies). Note that unsafe code is still managed code, i.e. it is compiled to IL, JITted, and run within the CLR.

Despite the fact that the above list appears to favour VB.NET (if you don't mind waiting for Whidbey), many people prefer C#'s terse syntax enough to make them use C# instead.

[Author: Jon Skeet]

Leave a Comment
  • Please add 6 and 1 and type the answer here:
  • Post
  • I don't think a discussion of VB6 vs VB.NET is really relevant to a C# FAQ.
  • Pls. let me know
  • How about any advantages over speed, I've read the entire fact and everything discused here has been about syntax.

    Does anyone have any facts about any speed advantages.
  • If written right, there is not speed difference. (i.e. if you use Directcast rather that CType and if you use Option Strict On and etc.) then it is almost 99% identical IL code.
  • One difference that has caused us a large amount of pain is VB not understanding operators denfined on some types. Take the System.Data.SqlTypes namespace for example. Even though there is an implicit operator from Int32 to SqlInt32, you can't use the following syntax in VB.NET

    Dim i As SqlInt32 = 10

    Instead you have to do either of the following

    Dim i as SqlInt32 = New SqlInt32(10)
    Dim i as SqlInt32 = SqlInt32.op_Implicit(10)

    I'm not sure how or why VB understands operators for some types in the System namespace but not others, but it is a real pain.

    Here's a couple of others to think about:
    1. Shared members are exposed in derived classes. For example, the static Object.Equals(objA, objB) will show up for every class as a shared member even though it's only defined in Object. Can make it pretty confusing as to who is actually doing the work. Especially if someone decides to shadow Object's implementation.
    2. No field attribute modifier. Try serializing an object where a form has a reference to an event on that object and you'll see what I mean.
    3. No escape character in strings. Console.WriteLine("The actor was quoted as saying ""now that's wierd""")
    4. How do you write an IIF in VB.NET where both return values are not evaluated even though only one will be returned. Try this and see what you get.

    Dim o As Object
    Console.WriteLine(IIf(True, "Good", o.ToString()))


  • OUT parameter will support by C#
  • Comparing vb to vb.net the main difference is the dotnet version is purely object oriented.
  • Assuming everything else (almost) equal, which one is faster to learn and get a handle on for a new starter?
  • I think that another advantage of C# over VB.NET is that C# is adhered to OOP theorical terminology like abstract, virtual, static, etc, while VB.NET use a propietary jerga (mustInherits, overridable, shared, etc).

    That is important when you read theory or use UML tools like Visio or Rational Rose.
  • How much faster is looping through unsafe arrays in C# compared to VB?
  • In other words, how do unsafe arrays in C# compare to the always managed arrays of VB?
  • C#とVB.NET の面白い比較投稿
  • Op de bijeenkomst van gisteren is door Frans Bouma en Maurice de Beijer strijd geleverd over de vraag...
Page 2 of 3 (42 items) 123