As a VB.NET programmer i only really use C# for XNA and other projects when i don't have a say on the matter. Recently i have begun to think about making a full blooded transition to C# after having some great success with it (specifically in XNA) and its not because VB.NET doesn't cut it. It is great but C# is also fantastic in my opinion, as it took features from some of the more distinguished languages avaliable, C++, Java and Object Pascal to name a few. Feature wise they are perfect for me no issues at all so before making any sort of decision i thought i would do a bit of research. So i decided to take a look at the MSIL of two simple applications in C# and VB.NET.
After comparing the MSIL of both this is what i realised:
- VB.NET contained 4 extra opcodes which were NOP (No Operation)
- VB.NET generated two extra variables (types Int32[] and Bool)
- VB.NET certainly used more OpCodes
The code was a simple for each loop like so:
Dim intArr()
As Integer = {1, 2, 3, 4}
For Each i
As Integer In intArr
Console.WriteLine(i.ToString())
Next
and..
int[] intArr = {1,2,3,4};
foreach (int i in intArr)
{
Console.WriteLine(i.ToString());
}
I am yet to test the execution speed of either application which will be one of my next tasks after a little more research. On a side note the C# code compiled was of size 5.0 kb and the VB.NET code compiled to 11.0 kb. I'll be sure to post more after i conduct some more research. Also note i am in no way trying to change peoples mind on what language to use, i don't believe the execution difference would be that noticeable anyway.
And here is another article which sort of explains the same thing as me but in a little more detail:
VB.NET vs C#: Performance