什么是“封闭”在C#中? [英] What are 'closures' in C#?

查看:108
本文介绍了什么是“封闭”在C#中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在.NET 瓶盖

什么是C#倒闭?

推荐答案

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

示例

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

您也可以看看 Martin Fowler的或的乔恩斯基特博客。我相信你将能够从他们的至少一个....

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

这篇关于什么是“封闭”在C#中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆