tags:

views:

2563

answers:

1

Duplicate

Closures in .NET

What are closures in C#?

+12  A: 

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....

cgreeno