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

  • Home
  • SEARCH
  • 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 7858447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:26:23+00:00 2026-06-02T21:26:23+00:00

I think this is a defered execution issue, but maybe i am missing the

  • 0

I think this is a defered execution issue, but maybe i am missing the point somewhat

I have a loop thus

List<int> processed = new List<int>()
foreach(KeyValuePair<int,bool> tbl1 in tables.Where(z=>!processed.Contains(z.Key))){
   //do some stuff...etc 
   processed.Add(someInt);
}

I feel this is very dangerous, but actually does the deferred execution make this work?
it does actually seem to be iterating i somewhat gently say ‘as expected’ but ….
question is I guess
presumably this is a bad idea, normally messing with a collection that you are iterating over is BAD..

thoughts?
thanks

ok to be clear..
the question is

say tables is filled like this

1,true
2,false
3,false
4,false
5,false
6,false

first lap I get the {1,true} in tbl1 and add say 2 to the processed list
on the second lap I would get {3,false} in the tbl1
then add 3 and 4 into processed
3rd lap I would get {5,false} in tbl1
is this expected?

if I on lap 4 added 6 to processed would I get {5,false} again on the next go around?
again is this expected
I guess I just find this somewhat confusing and feel its dangerous, but possibly that is just for me – as its not entirely making sense

n

  • 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-06-02T21:26:36+00:00Added an answer on June 2, 2026 at 9:26 pm

    As you iterate over tables it will always query the current contents of processed… so it will do what you want, but it’s not how I’d suggest doing it 🙂

    Aside from anything else, you could use HashSet<int> to avoid an O(n) containment check on each iteration.

    However, I suspect you want the functionality of DistinctBy in MoreLINQ:

    foreach (var item in tables.DistinctBy(x => x.Key))
    {
        // Process the item
    }
    

    That won’t leave you with a list of processed keys, admittedly… but maybe that’s not an issue.

    Personally I think it’s a shame that LINQ doesn’t already have DistinctBy, MaxBy etc, but there we go…

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

Sidebar

Related Questions

I think this must be simple but I can't get it right... I have
I think this is specific to IE 6.0 but... In JavaScript I add a
I think this is pretty typical, you have the same website project with an
I think this will be easy but I can't see how to do it!
I think this should be easy, but it's evading me. I've got a many-to-many
I think this must be a stupid question, but why do the results of
I have this method, that will be called against from a WCF Client, but
I think this may sound pretty simple, but still I can not get it
I think this property is quite useful, http://www.w3schools.com/Dom/prop_document_xml.asp But as you can see, it's
I think this problem is related to this question: Clicking submit clears file field

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.