Accessing generic lists with delegate notation

Posted by n0vic3c0d3r on Stack Overflow See other posts from Stack Overflow or by n0vic3c0d3r
Published on 2010-03-26T20:39:00Z Indexed on 2010/03/26 20:43 UTC
Read the original article Hit count: 203

Filed under:
|
|

I see some people write:

//wordList is List<string> 
wordList.ForEach(delegate(string word){ Console.WriteLine(word);});

instead of:

foreach(string word in wordList)
{
    Console.WriteLine(word);
}

What is the advantage in doing so. Also I couldn't fathom the Action delegate syntax given above though I have used delegates in C# 2.0. Basically I am not able to relate the syntax with the concept of delegates I am familiar with. Can you please help me understand the syntax. Is it some shorthand?

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET