What are 'closures' in C#?

Duplicate

Closures in .NET

What are closures in C#?


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 in parent's method body can be referenced from 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....

链接地址: http://www.djcxy.com/p/51082.html

上一篇: 在C#中有没有这样的“Javascript上下文”

下一篇: 什么是C#中的“闭包”?