Ugly thing and advantage of anonymos method -C#

Posted by nettguy on Stack Overflow See other posts from Stack Overflow or by nettguy
Published on 2010-03-26T19:30:19Z Indexed on 2010/03/26 19:33 UTC
Read the original article Hit count: 360

Filed under:
|
|
|

I was asked to explain the ugly thing and advantages of anonymous method.

I explained possibly

Ugly thing

anonymous methods turning quickly into spaghetti code.

Advantages

We can produce thread safe code using anonymous method :Example

static List<string> Names = new List<string>(
  new string[] {
    "Jon Skeet",
    "Marc Gravell",
    "David",
    "Bill  Gates"
  });

static List<string> FindNamesStartingWith(string startingText)
{
  return Names.FindAll(
    delegate(string name)
    {
      return name.StartsWith(startingText);
    });
}

But really i did not know whether it is thread safe or not.I was asked to justify it. Can any one help me to understand (1) advantages of anonymous methods (2) Is the above code thread safe or not?

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about c#