Sunday, April 3, 2011

What are 'closures' in C#?

Duplicate

Closures in .NET

What are closures in C#?

From stackoverflow
  • A closure in C# takes the form of an in-line delegate/anonymous method. A closure is attached to its parent method meaning that variables defined parents method body can be referenced within the anonymous method. There is a great Blog Post here about it.

    Example

    public Person FindById(int id)
    {
        return this.Find(delegate(Person p)
        {
            return (p.Id == id);
        });
    }
    

    You could also take a look at Martin Fowler or Jon Skeet blogs. I am sure you will be able to get a more "In Depth" breakdown from at least one of them....

0 comments:

Post a Comment