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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:00:33+00:00 2026-05-26T22:00:33+00:00

Today I ran into an issue with LINQ to objects (not SQL) that popped

  • 0

Today I ran into an issue with LINQ to objects (not SQL) that popped up due to a typo. I had a .Select one place and a .Where in another place. I was expecting same result but they are showing different numbers. Assume somelist has 10 elements with all elements having qty = 0

//returns 10 - basically count of all rows. I am expecting 0
 somelist.Select(p => p.qty > 0).Count() 

//returns 0 - the correct count
 somelist.Where(p => p.qty > 0).Count() 

if both select and where return IEnumerable<T> then why the ambiguity? Thank you.

  • 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-26T22:00:34+00:00Added an answer on May 26, 2026 at 10:00 pm

    Select is a projection, so what you get is the expression p.qty > 0 evaluated for each element in somelist. i.e. lots of true/false values (the same number as your original list). So when you do Count on it, you get the same number. If you look the select will return IEnumerable<bool> (because the type of p.qty > 0 is a bool).

    Where filters the results so count runs on the filtered list, and give you the expected results. The type of this is an IEnumerable<TypeOfElementInOriginalList>.

    Note you can also do: somelist.Count(p => p.qty > 0) because Count has an overload that accepts a predicate to filter by.

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

Sidebar

Related Questions

Ran into an issue today that I have not been able to resolve. I
I ran into an issue using a struct today that caught me off guard,
I ran into a weird situation today doing some one-time sql code. This nested
Today I ran into an issue using RoR to stub calls to AR objects.
I ran into an interesting issue today. I have canvas elements that I am
I ran into an interesting (and very frustrating) issue with the equals() method today
Today I ran into the following problem with NUnit. I have a class, that
So odd situation that I ran into today with OrderBy: Func<SomeClass, int> orderByNumber =
I just started playing around with threading today and I ran into something that
I ran into a situation today where Java was not invoking the method I

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.