Difference between VB.NET and C#


Difference between VB.NET and C#

This is the most debatable issue in .NET community and people treat there languages like religion. Its a subjective matter which language is best. Some like VB.NET's natural style and some like professional and terse C# syntaxes. Both use the same framework and speed is also very much equivalents. But still lets list down some major differences between them:

Advantages VB.NET

- Has support for optional parameters which makes COM interoperability much easy.
- With Option Strict off late binding is supported.Legacy VB functionalities can be used by using Microsoft.VisualBasic namespace.
- Has the WITH construct which is not in C#.
- 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.

Advantages of C#

- XML documentation is generated from source code but this is now been incorporated in Whidbey.
- Operator overloading which is not in current VB.NET but is been introduced in
Whidbey.
- The using statement, which makes unmanaged resource disposal simple.
- Access to 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).This is the major difference that you can access unmanaged code in C# and not in VB.NET.


Comments

Author: Phagu Mahato28 Dec 2013 Member Level: Gold   Points : 8

VB.NET


Support for optional parameters - very handy for some COM interoperability.
Support for named indexers.
Various legacy VB functions
The ability to implement interfaces with methods of different names.
The VB.NET parts of Visual Studio .NET compiles your code in the background. While this is considered as an advantage for small projects, people creating very large projects have found that the IDE slows down considerably as the project gets larger.

Visual Basic .NET can also force parameters to be passed by value, regardless of how they are declared, by enclosing the parameters in extra parentheses. There is no way to achieve this thing in C#.
 For Example:
Dim y As Integer = 15
Dim z As Integer
z = Add(y)
z = Add((y))

The Add function:
Public Function Add(ByRef x As Integer) As Integer
x = x + 1
Return x
End Function


C Sharp



XML documentation generated from source code comments.
Operator overloading - again, coming to VB.NET in Whidbey.
Language support for unsigned types
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 re-implemented separately in a derived class.
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 Note that unsafe code is still managed code
down vote accepted

References:
http://www.harding.edu/fmccown/vbnet_csharp_comparison.html
http://en.wikipedia.org/wiki/Comparison_of_C_Sharp_and_Visual_Basic_.NET
http://www.codeproject.com/KB/dotnet/vbnet_c__difference.aspx



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: