Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 157489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:30:48+00:00 2026-05-11T10:30:48+00:00

My co-worker said that in a previous interview, he learned that foreach is faster

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T10:30:48+00:00Added an answer on May 11, 2026 at 10:30 am

    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#)

    public void TestForEach()     {         List<string> items = new List<string> { 'one', 'two', 'three' };          foreach (string item in items)         {             Debug.WriteLine(item);         }     } 

    And in VB.Net:

    Public Sub TestForEach     Dim items As List(Of String) = New List(Of String)()     items.Add('one')     items.Add('two')     items.Add('three')     For Each item As string In items         Debug.WriteLine(item)     Next End Sub 

    Here is the IL for the C# version:

    .method public hidebysig instance void TestForEach() cil managed {     .maxstack 2     .locals init (         [0] class [mscorlib]System.Collections.Generic.List`1<string> items,         [1] string item,         [2] class [mscorlib]System.Collections.Generic.List`1<string> <>g__initLocal3,         [3] valuetype [mscorlib]System.Collections.Generic.List`1/Enumerator<string> CS$5$0000,         [4] bool CS$4$0001)     L_0000: nop      L_0001: newobj instance void [mscorlib]System.Collections.Generic.List`1<string>::.ctor()     L_0006: stloc.2      L_0007: ldloc.2      L_0008: ldstr 'one'     L_000d: callvirt instance void [mscorlib]System.Collections.Generic.List`1<string>::Add(!0)     L_0012: nop      L_0013: ldloc.2      L_0014: ldstr 'two'     L_0019: callvirt instance void [mscorlib]System.Collections.Generic.List`1<string>::Add(!0)     L_001e: nop      L_001f: ldloc.2      L_0020: ldstr 'three'     L_0025: callvirt instance void [mscorlib]System.Collections.Generic.List`1<string>::Add(!0)     L_002a: nop      L_002b: ldloc.2      L_002c: stloc.0      L_002d: nop      L_002e: ldloc.0      L_002f: callvirt instance valuetype [mscorlib]System.Collections.Generic.List`1/Enumerator<!0> [mscorlib]System.Collections.Generic.List`1<string>::GetEnumerator()     L_0034: stloc.3      L_0035: br.s L_0048     L_0037: ldloca.s CS$5$0000     L_0039: call instance !0 [mscorlib]System.Collections.Generic.List`1/Enumerator<string>::get_Current()     L_003e: stloc.1      L_003f: nop      L_0040: ldloc.1      L_0041: call void [System]System.Diagnostics.Debug::WriteLine(string)     L_0046: nop      L_0047: nop      L_0048: ldloca.s CS$5$0000     L_004a: call instance bool [mscorlib]System.Collections.Generic.List`1/Enumerator<string>::MoveNext()     L_004f: stloc.s CS$4$0001     L_0051: ldloc.s CS$4$0001     L_0053: brtrue.s L_0037     L_0055: leave.s L_0066     L_0057: ldloca.s CS$5$0000     L_0059: constrained [mscorlib]System.Collections.Generic.List`1/Enumerator<string>     L_005f: callvirt instance void [mscorlib]System.IDisposable::Dispose()     L_0064: nop      L_0065: endfinally      L_0066: nop      L_0067: ret      .try L_0035 to L_0057 finally handler L_0057 to L_0066 } 

    Here is the IL for the VB.Net version:

    .method public instance void TestForEach() cil managed {     .maxstack 2     .locals init (         [0] class [mscorlib]System.Collections.Generic.List`1<string> items,         [1] string item,         [2] valuetype [mscorlib]System.Collections.Generic.List`1/Enumerator<string> VB$t_struct$L0,         [3] bool VB$CG$t_bool$S0)     L_0000: nop      L_0001: newobj instance void [mscorlib]System.Collections.Generic.List`1<string>::.ctor()     L_0006: stloc.0      L_0007: ldloc.0      L_0008: ldstr 'one'     L_000d: callvirt instance void [mscorlib]System.Collections.Generic.List`1<string>::Add(!0)     L_0012: nop      L_0013: ldloc.0      L_0014: ldstr 'two'     L_0019: callvirt instance void [mscorlib]System.Collections.Generic.List`1<string>::Add(!0)     L_001e: nop      L_001f: ldloc.0      L_0020: ldstr 'three'     L_0025: callvirt instance void [mscorlib]System.Collections.Generic.List`1<string>::Add(!0)     L_002a: nop      L_002b: nop      L_002c: ldloc.0      L_002d: callvirt instance valuetype [mscorlib]System.Collections.Generic.List`1/Enumerator<!0> [mscorlib]System.Collections.Generic.List`1<string>::GetEnumerator()     L_0032: stloc.2      L_0033: br.s L_0045     L_0035: ldloca.s VB$t_struct$L0     L_0037: call instance !0 [mscorlib]System.Collections.Generic.List`1/Enumerator<string>::get_Current()     L_003c: stloc.1      L_003d: ldloc.1      L_003e: call void [System]System.Diagnostics.Debug::WriteLine(string)     L_0043: nop      L_0044: nop      L_0045: ldloca.s VB$t_struct$L0     L_0047: call instance bool [mscorlib]System.Collections.Generic.List`1/Enumerator<string>::MoveNext()     L_004c: stloc.3      L_004d: ldloc.3      L_004e: brtrue.s L_0035     L_0050: nop      L_0051: leave.s L_0062     L_0053: ldloca.s VB$t_struct$L0     L_0055: constrained [mscorlib]System.Collections.Generic.List`1/Enumerator<string>     L_005b: callvirt instance void [mscorlib]System.IDisposable::Dispose()     L_0060: nop      L_0061: endfinally      L_0062: nop      L_0063: ret      .try L_002c to L_0053 finally handler L_0053 to L_0062 } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 82k
  • Answers 82k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer without seeing the html I would say check your path.… May 11, 2026 at 4:40 pm
  • Editorial Team
    Editorial Team added an answer I would think you could just replace your the table… May 11, 2026 at 4:40 pm
  • Editorial Team
    Editorial Team added an answer Wow, I was royally screwing up. Of course ModelMultipleChoiceField doesn't… May 11, 2026 at 4:40 pm

Related Questions

I recently wrote a DLL in C# (.Net 2.0) which contains a class that
I'm code reviewing a change one of my co-workers just did, and he added
I'm attempting to create my first real C# application - a small pet project
Asking on behalf of my coworker: We're working on a Facebook app that uses

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.