being verifiable

Comparison of C Sharp and Visual Basic .NET

The original .NET Framework distributions from Microsoft included several language-to-IL compilers, including the two primary languages: C# and Visual Basic. There is heated debate among the greater .NET community about which language is better in general, or for specific purposes. Below is a comparison of the two languages.


It should be noted that all .NET programming languages share the same runtime engine, and when compiled produce binaries that are seamlessly compatible with other .NET programming languages, including cross language inheritance, exception handling, and debugging.

No second class languages

One of the main goals of .NET has been its multi language support, and the concept of "no second class languages". That is, all of the various Microsoft languages should have the same level of access to all OS features, and all expose the same level of power and usability.

It should be noted that Visual Basic and Visual Basic .NET are completely different languages and are not backwards-compatible. Visual Basic .NET shares only syntax similarities with Visual Basic. The Abstract syntax tree for Visual Basic .NET and C# are closely matched and the intermediate language produced by the compiler is virtually identical. It is possible to compile C# code into IL and use a decompiler to convert the compiled IL back into Visual Basic .NET source code - such is the similarity between the languages.

C# shares syntax similarities with Java. Both C# and Visual Basic .NET share structural similarities with other modern high level languages such as Java and C++. However the differences between Java and .NET are numerable, as can be seen in Comparison of Java and C Sharp.

Development Environment

Visual Studio provides minor differences in the development environment for C# and VB.Net. With the release of subsequent versions of Visual Studio the differences between the languages have reduced. For instance early versions of Visual Studio had poor support for Intellisense in C# compared to Visual Basic .NET.

Exclusive C# Development Environment Features

Exclusive VB.Net Development Environment Features

  • Visual Studio for VB.NET has a background compiler that displays intellisense errors automatically in the code editor
  • Default namespace is hidden (can be disabled)
  • Certain project files are hidden (user can show them)
  • A namespace My lists a lot of functions shortcuts (using the registry, application-specific functions, etc..)
  • A delegate can be made using AddressOf myObject.theFunction

Language features

The bulk of the differences between C# and VB.NET from a technical perspective are syntactic sugar. That is, most of the features are in both languages, but some things are easier to do in one language than another. Many of the differences between the two languages are actually centered around the IDE.

Features common to all .Net languages

These features are common to both C# and VB.Net as well as all languages running the .Net platform.

  • Garbage collection

Features of Visual Basic .NET not found in C#

  • Auto-wireup of events, VB.NET has the Handles syntax for events.
  • Support for optional variables. Visual Basic .NET is better suited for DLL interoperability which is a particular advantage for automating Microsoft Office
  • Marshalling an object for multiple actions using an unqualified dot reference. This is done using the With...End With structure.

Features of C# not found in Visual Basic .NET

  • Supports unsafe code blocks for improved performance at the expense of not being verifiable as "safe" by the runtime
  • Anonymous methods
  • Partial Interfaces
  • Iterators and the yield keyword
  • Multi-line comments (note that the Visual Studio IDE supports multi-line commenting for Visual Basic .NET)
  • Static classes (Classes which cannot contain any non-static members, although VB's Modules are essentially sealed static classes with additional semantics)
  • Can use checked and unchecked contexts for fine-grained control of overflow/underflow checking

Criticisms of Visual Basic .NET not applicable to C#

  • Optional strong typing
  • Conversion of Boolean value True to Integer may yield -1 or 1 depending on the conversion used
  • Assigning and comparing variables uses the same token, =. Whereas C# has separate tokens, == for comparison and = to assign a value.
  • Can't perform operator overloading. C# example: Week wk2 = wk1 + 1; However, since VB .NET 2005, this is possible

Criticisms of C# not applicable to Visual Basic .NET

  • By default, numeric operations are not checked. This results in slightly faster code, at the risk that numeric overflows will not be detected. However, the programmer can place arithmetic operations into a checked context to activate overflow checking.
  • Lack of optional parameters in functions, a feature present in both Visual Basic.NET and C++.
  • In Visual Basic .NET property methods may take variables
  • Visual Basic .NET has better interoperability with older versions of Microsoft Office (In term of native VBA language for Office still is Visual Basic 6.X, not Visual Basic.NET)
  • C# is case sensitive so it is possible to have two variables with the same name, eg variable1 can be different to Variable1. Visual Studio will correct the case of variables as they are typed in VB.NET. However, case sensitivity is fairly natural in some cases. For instance the argument of function : public int CalculateOrders(Customer customer)

Syntax comparisons

Visual Basic .NET terminates a block of code with End BlockName or Next for a for loop which is more familiar for programmers with experience using T-SQL. In C#, the braces, {}, are use to delimit blocks, which is more familiar to programmers with experience in other modern languages such as C++ and Java.

In C#, when a block is not defined for a statement, the next statement will be treated as the block.

Sometimes C# developers will add comments at the end of scope to more easily mark where the scope started. For instance some C# developers use } // End If to mark the end of a nested if statement. This can negate the argument that C# is a cleaner language to read.


Keywords are very different between the two languages.

A comparison: (VB.NET vs C#)

  • Me vs this - a self-reference to the current object instance
  • MyBase vs base - for referring to the base class from which the current class is derived
  • Shared vs static - for declaring methods that do not require an explicit instance of an object
  • NotInheritable vs sealed - for declaring classes that may not be inheritedREDIRECT:
  • NotOverridable vs sealed - for declaring methods that may not be overridden by derived classes
  • MustInherit vs abstract - prevents a class from being directly instantiated, and forces consumers to create objects references to only derived classes
  • MustOverride vs abstract - for forcing derived classes to override this method
  • Overridable vs virtual - declares a method as being able to be overridden in derived classes

Notice above how some C# keywords such as sealed are used to represent different things when applied to method or class definitions. VB.NET, on the other hand, uses different keywords for different context


C# Visual Basic .NET
// Single Line Comment ' Single Line Comment
/* Multi-line comment */ not available
/// Single Line XML Comment ''' Single Line XML Comment
/** Multi-line XML comment */ not available

Note that for Visual Basic .NET, multiple lines of code can be commented or uncommented using the Visual Studio IDE. As such having no support for Multi-line comments in the language is a disadvantage only when the IDE is not used.


C# Visual Basic .NET
if (condition) {
   // condition is true
If condition Then
   ' condition is true
End If
if (condition) {
   // condition is true
} else {
   // condition is false
If condition Then
   ' condition is true
   ' condition is false
End If
if (condition) {
   // condition is true
} else if (othercondition) {
   // condition is false and othercondition is true
If condition Then
   ' condition is true
ElseIf othercondition Then
   ' condition is false and othercondition is true
End If
if (condition) {
   // condition is true
} else if (othercondition) {
   // condition is false and othercondition is true
} else {
   // condition and othercondition are false
If condition Then
   ' condition is true
ElseIf othercondition Then
   ' condition is false and othercondition is true
   ' condition and othercondition false
End If

For loop

C# Visual Basic .NET
for (int i = 0; i < number; i++) {
   // loop from zero up to one less than number
For i As Integer = 0 To number - 1
   ' loop from zero up to one less than number
for (int i = number; i >= 0; i--) {
   // loops from number down to zero
For i As Integer = number To 0 Step -1
   ' loops from number down to zero

Equality and other comparison operators

C# Visual Basic .NET
if (a == b) {
   // equal
If a = b Then
   ' equal
End If
if (a != b) {
   // not equal
If a <> b Then
   ' not equal
End If
if ((a == b) & (c == d) | (e == f)) {
   // multiple comparisons
If a = b And c = d Or e = f Then
   ' multiple comparisons
End If
if ((a == b) && (c == d) (e == f)) {
   // short-circuiting comparisons
If a = b AndAlso c = d OrElse (e = f) Then
   ' short-circuiting comparisons
End If
if (a is b) {
   // type compatibility operator
If TypeOf a Is b Then
   ' type compatibility operator
End If


Adoption and community support

Both C# and VB.Net have high adoption rates, and very active developer communities and Microsoft fully supports both communities. However, C# does have an advantage in terms of the level of community activity on the Internet. Also, there are more books available for C# than VB.Net, and publishers report that C# books significantly outsell the VB.Net counterparts.

Examples of the increased community and industry adoption include:

  • According to a survey conducted by Visual Studio Magazine (which self-identifies as a VB centric publication) "41 percent said they used C#, 34 percent programmed in VB.NET, while 25 percent responded with 'other.'"
  • Stephen Wiley, marketing product manager at Apress has reported "C# titles outsell VB.NET title books handily, by somewhere between a 2–1 and 3–1 margin."
  •, the blogging site for Microsoft employees, has 27,500 posts that discuss C#, while only 8,880 mention VB.Net (November 15, 2007)
  • Google Groups, a Usenet search engine returns 36,900 hits for "VB .Net", and 65,700 for C#
  • Amazon returns 9,923 hits for C#, and 2,149 hits for "Visual Basic .Net" (November 15, 2007).
  • Telerik Survey 2008 suggested that C# (63%) had surpassed VB.NET (34%) as the primary programming language.

As counter examples

  • VB.NET is the most popular download of all the Express downloads. C++ is the most popular download among students. 80 percent of all downloads for the Express line were by non-professionals.

Other languages

C++/CLI (formerly Managed C++)

C++/CLI (a replacement for Managed Extensions for C++) does not have the adoption rate of C# or VB.NET, but does have a significant following. C++/CLI syntactically, stylistically, and culturally is closest to C#. However, C++/CLI stays closer to its C++ roots than C# does. C++/CLI directly supports pointers, deconstructors, and other unsafe program concepts which are not supported or limited in the other languages. It allows the direct use of both .NET code and standard C++ code. C++/CLI is used for porting native/legacy C++ applications into the .NET framework, or cases where the programmer wants to take more control of the code; but this control comes at a significant cost of ease of use and readability. Many of the automated tools that come with Visual Studio have reduced functionality when interacting with C++ code. This is because reflection cannot provide as much information about the code as it can for C# and


J# runs a distant fourth in terms of adoption. J# is a language primarily designed to ease the transition of Java applications to the .NET framework; it allows developers to leave much of their Java or J++ code unchanged while still running it in the .NET framework, thus allowing them to migrate small pieces of it into another .NET language, such as C#, individually. J# does not receive the same level of updates as the other languages, and does not have the same level of community support. For example, Visual Studio 2005 supports automatic generation of Unit Tests in C#, VB.Net, and C++, but excludes J#. J# is not included with Visual Studio 2008 and thus discontinued.

Minor languages

There are many additional languages available for the .NET Platform.


All .NET languages compile down to Common Intermediate Language (CIL) , but it is also possible to code directly in CIL. This can be done for performance or security reasons, or just for fun. It is a common practice to make source changes in the original C# or VB.NET, and then compare the resulting CIL, to see what benefits or consequences might result . Coding directly in CIL often makes code that is difficult or impossible to de-compile to a higher level language like C#. Either the decompile fails, or the resulting code is not very readable. This is analogous to writing directly in assembly language, and then decompiling to C++. This technique is used by many obfuscators to help prevent reverse-engineering. It is possible to code an entire application directly in CIL, but this would be very cumbersome.


External links

Search another word or see being verifiableon Dictionary | Thesaurus |Spanish
Copyright © 2015, LLC. All rights reserved.
  • Please Login or Sign Up to use the Recent Searches feature