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

MSDN gives this sample code in an 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 that all this does. What i don't understand is

Select(str => str)

Little. Is it really not necessary? If you leave it and just

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

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

Am I missing something, or is this a misleading example?

+5
source share
4 answers

Select really redundant.

I suspect that this example may have been “translated” from the syntax for understanding the request, as in:

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

Select , , . Where , .

, , . MSDN !

+9

, .

, , , .. . , List<T>, IEnumerable<T>, . , , , , , , :

public IEnumerable<T> Items
{
   get { return privateList.Select(i => i); }
}
+1

, , msdn page. : " ". , Select :

Select(str => str)

0

. TOC, :

"[ . .]"

The first line also looks like the author’s comment to himself.

And since VS 2010 and .NET 4.0 have just been released, I think this is a kind of broken theme that has not been removed / replaced in time.

I think the correct URL for this content is the following: http://msdn.microsoft.com/en-us/library/bb534303.aspx

By the way, how did you get your URL? Was it through an MSDN search or something else?

0
source

All Articles