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 6325545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:54:54+00:00 2026-05-24T16:54:54+00:00

According to the language specification guide for VB.NET Section 10.9.3 The enumerator expression in

  • 0

According to the language specification guide for VB.NET Section 10.9.3

The enumerator expression in a for each loop is copied over into
memory.

If I have a list of 10000 objects that list will be in memory twice for the code below?

dim myList as new list(of bobs)
'put 10000 bobs in my list
for each x In myList
'do something 
next

If I were generating the list from a linqQuery or some other such query it would make sense to generate that list at the for each loop statement thus not having the list in memory twice for example.

for each x in myList.where(function(x) x.name = Y)
'do something
next

If the LINQ query is unreadable on the for each loop, do I forgo readability and just put it on the for each loop declaration line?

Should I declare the list in its own variable and just bite the bullet and have the list exist twice in memory?

  • 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. Editorial Team
    Editorial Team
    2026-05-24T16:54:54+00:00Added an answer on May 24, 2026 at 4:54 pm

    that list will be in memory twice for the code below

    No, it won’t. In your case, the spec is talking about the variable “x” here – not the entire collection. Remember, and enumerator (any IEnumerable<T> or similar) doesn’t necessarily even have items in memory. When created via an iterator in C#, for example, you can have “collections” that are generated as you enumerate over them. There isn’t a “list” of objects (necessarily) that could be copied, even if the language wanted to do so.

    Is the linq query is unreadable on the for each loop

    In many cases, I prefer filtering this way. You can just as easily move this outside of the loop, if you want to make it more clear, as well:

    Dim filteredCollection = myList.Where(Function(x) x.name = Y)
    For Each x in filteredCollection
    

    There is no disadvantage to doing this if you find it more readable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

According to the Java Language Specification : If there are any enclosing try statements
According to the ECMAScript specification in section 7.8.1 a NullLiteral is defined as follows:
According to the Java Language Specification , constructors cannot be marked synchronized because other
According to the Java Language Sepecification , 3rd edition: It is a compile-time error
According to what I have found so far, I can use the following code:
I would like to have a GnomeCanvas text item and according to its content
I have gvim 7.2, it recognizes .d files and highlights it correctly according to
According to you, which language do you think would be the best for implementing
I am new to assembly language. I have written a program for taking an
According to language benchmarks , JavaScript V8 is faster than other programming languages at

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.