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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:53:55+00:00 2026-05-14T08:53:55+00:00

The MSDN gives this code example in the article on the Func Generic Delegate

  • 0

The MSDN gives this code example in the article on the Func Generic Delegate:

Func<String, int, bool> predicate = ( str, index) => str.Length == index;

String[] words = { "orange", "apple", "Article", "elephant", "star", "and" };
IEnumerable<String> aWords = words.Where(predicate).Select(str => str);

foreach (String word in aWords)
    Console.WriteLine(word);

I understand what all this is doing. What I don’t understand is the

Select(str => str)

bit. Surely that’s not needed? If you leave it out and just have

IEnumerable<String> aWords = words.Where(predicate);

then you still get an IEnumerable back that contains the same results, and the code prints the same thing.

Am I missing something, or is the example misleading?

  • 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-14T08:53:56+00:00Added an answer on May 14, 2026 at 8:53 am

    The Select is indeed redundant.

    I suspect that this example may have been “translated” from the query comprehension syntax, as in:

    IEnumerable<String> aWords = 
        from w in words
        where (...)
        select w;
    

    When using this syntax, you have to select at the end, it’s just how the compiler works. When using the Where extension method, however, it’s completely unnecessary unless you actually need to do a separate projection.

    Or, maybe it’s just a mistake. The MSDN writers aren’t infallible!

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

Sidebar

Related Questions

Looking at the example code on MSDN : This ' Declares a type. Dim
I use this code to encrypt a string (basically, this is the example given
Is the advice given in this oft-cited MSDN article still considered sound for converting
This is my code: int main() { const int LEN = 5; int x[LEN];
the second function gives error C2803 http://msdn.microsoft.com/en-us/library/zy7kx46x%28VS.80%29.aspx : 'operator ,' must have at least
MSDN states that String.Intern retrieves the system's reference to the specified String and String.IsInterned
MSDN docs say that only value types need boxing, but this does not apply
I have a loop in my C++/OpenMP code that looks like this: #pragma omp
In this document, http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx#paths To make these device objects accessible by Windows applications, the
I've been reading about the this pointer on various sites (e.g. the MSDN manuals)

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.