Why does this MSDN example for Func<> delegate have a superfluous Select() call?

Posted by Dan on Stack Overflow See other posts from Stack Overflow or by Dan
Published on 2010-04-25T15:04:42Z Indexed on 2010/04/25 15:13 UTC
Read the original article Hit count: 151

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about c#

Related posts about MSDN