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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:35:52+00:00 2026-05-20T01:35:52+00:00

I wonder how LINQ to Objects determines the best way to query in a

  • 0

I wonder how LINQ to Objects determines the best way to query in a collection ?

I mean, is there any difference (in how LINQ works internally) between the following LINQ queries:

var lst1 = ListOfComplexClass.Where(p => p.StrValue == "Whatever")
                             .Select(p => p.StrValue);

And

var lst2 = ListOfComplexClass.Select(p => p.StrValue)
                             .Where(p => p == "Whatever");

For example, will the first one filter the collection of ListOfComplexClass and then get the StrValue property?
Or will it do some tuning and execute the Select first and then filter the returned collection?

  • 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-20T01:35:53+00:00Added an answer on May 20, 2026 at 1:35 am

    For example.. will the first one filter the collection of ListOfComplexClass and then get the StrValue property? Or it’ll make some maybe tunning and execute the Select first and then filter the returned collection?

    (I am assuming that you meant p => p.StrValue in the Select in the first one.)

    Actually, it’s more subtle than that.

    Let us say that you take an enumerator on the first one.

    var lst1 = ListOfComplexClass.Where(p => p.StrValue == "Whatever")
                                 .Select(p => p.StrValue);
    var e = lst1.GetEnumerator();
    

    When you call e.MoveNext(), what will happen is that Select will call MoveNext() on an iterator of ListOfComplexClass.Where(p => p.StrValue == "Whatever") which will call MoveNext() an iterator of ListOfComplexClass until it finds an element p with p.StrValue == "Whatever". Then, the projected result of this p will be returned as e.Current.

    Now let us consider the second one. Let us say that you take an enumerator of it.

    var lst2 = ListOfComplexClass.Select(p => p.StrValue)
                                 .Where(p => p == "Whatever");
    var e = lst2.GetEnumerator();
    

    When you call e.MoveNext(), Where will call MoveNext() on an iterator of ListOfComplexClass.Select(p => p.StrValue) until it finds an element p with p == "Whatever". Of course, calling MoveNext() on an iterator of ListOfComplexClass.Select(p => p.StrValue) will call MoveNext() on an iterator of ListOfComplexClass and return the projection of Current for that iterator.

    Jon Skeet has a good analogy which I’ll steal here. Imagine a deck of cards in random order. Imagine the queries

    var suits = deck.Where(c => c.Suit == Suit.Diamond || c.Suit == Suit.Heart)
                    .Select(c => c.Suit)
    

    and

    var suits = deck.Select(c => c.Suit)
                    .Where(c => c == Suit.Diamond || c == Suit.Heart);
    

    Now imagine consuming the result of the first query. It goes like this.

    Select asks Where for a card.

    Where asks deck for a card.

    *Where checks the suit of the card.

    If the suit of the card is a diamond or a heart, it returns the card to the Select and Select projects the card to its suit and returns it.

    If the suit of the card is not a diamond or a heart, Where asks for another card from deck and loops back to *.

    The second query goes like this.

    Where asks Select for a suit.

    Select asks deck for a card.

    deck returns a card to Select.

    Select projects the card to its suit.

    *Where checks the suit from the Select.

    If the suit is a diamond or a heart, Where returns the suit.

    If the suit is not a diamond or a heart, Where asks Select for another suit and loops back to *.

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

Sidebar

Related Questions

I wonder, if someone could help me... Is there a LINQ query that will
I wonder how is the best way to integrate Java modules developed as separate
I wonder if there are any game engine written in Scala or easily accesible
I was wonder what would be the best way to log changes made to
I wonder if there is some way to know full paths to the dll's
I am using LINQ to Objects and wonder if it is possible to improve
I wonder if someone can help me with this. I have a LINQ query
I wonder if someone can help me translate a MySQL query to a (Db)LINQ
I was thinking about the way linq computes and it made me wonder: If
I'm just finding my way with WPF/Datagrid/Linq and I'm trying to find out how

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.