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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:06:06+00:00 2026-06-17T15:06:06+00:00

I got in a discussion with two colleagues regarding a setup for an iteration

  • 0

I got in a discussion with two colleagues regarding a setup for an iteration over an IEnumerable (the contents of which will not be altered in any way during the operation). There are three conflicting theories on which is the optimal approach. Both the others (and me as well) are very certain and that got me unsure, so for the sake of clarity, I want to check with an external source.

The scenario is as follows. We had the code below as a starting point and discovered that some of the hazaas need not to be acted upon. So, starting with the code below, we started to add a blocker for the action.

foreach(Hazaa hazaa in hazaas) ;

My suggestion is as follows.

foreach(Hazaa hazaa in hazaas.Where(element => condition)) ;

One of the guys wants to resolve it by a more explicit form, claiming that LINQ is not appropriate in this case (not sure why it’d be so but he seems to be very convinced). He’s solution is this.

foreach(Hazaa hazaa in hazaas) ;
  if(condition) ;

The other contra-suggestion is supported by the claim that Where risks to repeat the filtering process needlessly and that it’s more certain to minimize the computational workload by picking the appropriate elements once for all by Select.

foreach(Hazaa hazaa in hazaas.Select(element => condition)) ;

I argue that the first is obsolete, since LINQ can handle data objects quite well.

I also believe that Select-ing is in this case equivalently fast to Where-ing and no needless steps will be taken (e.g. the evaluation of the condition on the elements will only be performed once). If anything, it should be faster using Where because we won’t be creating an extra instance of anything.

Who’s right?

  • 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-17T15:06:08+00:00Added an answer on June 17, 2026 at 3:06 pm

    Select is inappropriate. It doesn’t filter anything.
    if is a possible solution, but Where is just as explicit.
    Where executes the condition exactly once per item, just as the if. Additionally, it is important to note that the call to Where doesn’t iterate the list. So, using Where you iterate the list exactly once, just like when using if.

    I think you are discussing with one person that didn’t understand LINQ – the guy that wants to use Select – and one that doesn’t like the functional aspect of LINQ.

    I would go with Where.

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

Sidebar

Related Questions

Following on from a discussion which got going in the comments of this question
Today at work we got into a discussion about which is the best way
From Richter and this discussion , I would expect any two identical strings to
Another person in my office and I got into a discussion about which complex
I got into an interesting discussion in a forum where we discussed the naming
Got a problem with Apache and PHP-files of Wordpress. When I go to any
I've got two web portals that are almost identical in architecture. One requires that
In an application I'm creating, I've got two components that I want the user
Suppose we've got two integer and character variables: int adad=12345; char character; Assuming we're
Recently I got into a discussion with my Team lead about using temp variables

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.