My co-worker said that in a previous interview, he learned that foreach is faster in VB.Net than c#’s foreach. He was told that this was because both have different CLR implementation.
Coming from a C++ perspective, I’m curious on why this is and I was told that I need to read up on CLR first. Googling foreach and CLR doesn’t help me understand.
Does anyone have a good explanation on why foreach is faster in VB.Net than in c#? Or was my co-worker misinformed?
There is no significant difference at the IL level between C# and VB.Net. There are some additional Nop instructions thrown in here and there between the two versions, but nothing that actually changes what is going on.
Here is the method: (in C#)
And in VB.Net:
Here is the IL for the C# version:
Here is the IL for the VB.Net version: