Tag Archives: VB.NET

C# & VB.Net

So over the past few weeks, I’ve been active on the MSDN forums for quite a bit. And there was one discussion that kept popping up every x days, the big question and source of discussion to lots of developers. Is C# better than VB.net, or isn’t it?

Truth is, there are quite a bit of difference but when you break the languages down to their core, they are the same. Picture this as being 2 cars. C# is a 2-door green car, and VB is a 4-door blue car. These 2 don’t look alike whatsoever, but inside they have the same features. Both have a steering wheel, radio, SatNav and whatnot. Think about this for a second, and read on to break down 2 of the most important languages there are.

If you got the picture, you will realise that what I’m trying to explain, is that the two languages don’t look alike on the surface, but inside they are the same.
Let’s cover the most obvious difference, as silly as it might sound. The whole layout of VB is blue, and the whole layout of C# is green. Not coincidentally the colours of the cars I used to illistrate this matter.

Once you have launched your editor, you can start programming. Here is where we encounter our second difference, and probably the most important one to notice.

The whole syntax of the  2 languages are like apples and pears.

As you can tell by these little snippets, the code is equally readable. But C# closes and opens a scope using the curly braces ( {} ).  Whereas in VB it opens and closes using code ( Sub & End Sub / Module & End Module). C# also indicated changed & saved code snippets. Using the green line at the right of the code explorer.

Furthermore there are differences in the language, for example: C# is case-sensitive whearas VB.Net is not.. Another difference is the Keywords used to refer to the underlying datatypes. And C# does support some datatypes which Visual Basic does not.

Visual Basic .NET Visual C# .NET .NET Framework
Boolean bool System.Boolean
Byte byte System.Byte
Short short System.Int16
Integer int System.Int32
Long long System.Int64
Single float System.Single
Double double System.Double
Decimal decimal System.Decimal
Date System.DateTime System.DateTime
String string System.String
Char char System.Char
Object object System.Object
n/a sbyte System.Sbyte
n/a ushort System.UInt16
n/a uint System.UInt32
n/a ulong System.UInt64

 

But let’s look at this code we have written earlier in this article, by using ILDASM, so we can break down the code to the Intermediate Language.

In essence they do look the same. So ILDASM shows us what’s inside our car (.net language).

And yes, it’s given that C# has some small things VB.net seems to lack at the moment I’m writing this, as shown in the table above. But in a few years, both of these languages look alot more alike, at microsoft they strive to make the languages an equal to eachother.

So why the discussions? What makes the difference?
One simple word: Taste. What makes people like the green car over the blue car? Taste, preference, and in some cases their habit.
I started out programming in VB.net, and I have loved the language (in a pure platonic way ofcourse) as long as I’ve used it. Recently I switched to C#, the only reason being that I like the syntax more.

So to wrap it up: C# shows small differences with VB.Net, but both are equally powerfull languages because they both use the CLR. So it’s really just a matter of preference.

(If you want a full list of the syntax differences you can look at the white paper published by Microsoft)