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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:24:31+00:00 2026-05-27T08:24:31+00:00

Even though Select operator gets called before the Take operator, the lambda expression will

  • 0

Even though Select operator gets called before the Take operator, the lambda expression will only get called for the first two input elements:

        string[] count = { "one ", "two ", "three ", "four ", "five ", "six " };
        IEnumerable<int> results = count.Select(item =>
                               {
                                      Console.WriteLine(item);
                                      return item.Length;
                               }).Take(2); 
        foreach (int i in results);

OUTPUT:

one two 

a) Assuming we chain several Linq-to-Objects standard query operators together, is the order in which Take operator gets called never important? Thus, it never matters whether Take gets called first or last, since the number of input elements for which the lambda expression will be called is always the same?

b) Again assuming we chain several Linq-to-Objects standard query operators together, are there any other Linq-to-Objects operators where the order in which they are called doesn’t affect the number of input elements for which the lambda expression gets called?

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-27T08:24:31+00:00Added an answer on May 27, 2026 at 8:24 am

    Query operators typically only move as many steps forward in the source collection as they need to produce the number of required output results.

    In your example Take() will only require 2 items from Select() so that’s all that will be produced by Select(). Select() is probably implemented roughly like this (taken from Jon Skeet’s blog:

    private static IEnumerable<TResult> Select<TSource, TResult>( 
        this IEnumerable<TSource> source, 
        Func<TSource, TResult> selector) 
    { 
        foreach (TSource item in source) 
        { 
            yield return selector(item); 
        } 
    }
    

    Sorting and grouping operators will need to create the full result set before being able to return anything (e.g. OrderBy()).

    As long as you don’t use any ordering, grouping, filtering (such as with Where() or Skip()) or any other operator changing the number of items in the sequence it shouldn’t matter where in the chain you put the Take().

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

Sidebar

Related Questions

var lastitem = Contacts .OrderByDescending(c => c.ContactID) .Take(1).Select(p=>p.ContactID); lastitem is even though a single
I saw that __VIEWSTATE field gets rendered even though I have set the EnableViewState=false
In PowerShell I have tried: alias | select-string Alias This fails even though Alias
I need to select a row only from two corresponding tables, for instance, member
First of all I'm rather new to SQL and so even though I believe
Is anyone able to explain why the two results are different, even though the
Even though I always strive for complete validation these days, I often wonder if
Even though I have a robust and fast computer (Pentium Dual Core 2.0 with
Even though I've been a developer for awhile I've been lucky enough to have
Even though MDI is considered harmful , several applications (even MS Office, Adobe apps)

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.