有人可以向我解释匿名方法吗? [英] Can someone explain Anonymous methods to me?

查看:95
本文介绍了有人可以向我解释匿名方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Delphi 2009,在一些很酷的东西中,也有匿名的方法。我看过的例子,和博客文章有关匿名方法,但我还没有得到他们。有人能解释为什么我应该兴奋吗?

Delphi 2009, among some cool stuff, has also just got Anonymous methods. I've seen the examples, and the blog posts regarding anonymous methods, but I don't get them yet. Can someone explain why I should be excited?

推荐答案

只需考虑典型的回调代码, 。通常,此数据仅用于回调(仅),但您必须跳过一些圈才能获得它,而无需退出un-OOP友好实践(如全局变量)。使用匿名方法,数据可以保留在它的位置 - 您不必不必要地扩展其范围或将其复制到一些帮助器对象。只需将回调代码作为匿名方法就地写入,并且可以在定义匿名方法的站点(而不是调用它的地方)完全访问和操作所有局部变量。

Just think of typical callback code where you need to have data available to the callback. Often this data is needed for the callback only, yet you have to jump through a number of hoops to get it there without having to resign to un-OOP-friendly practices like global variables. With anonymous methods the data can stay where it is - you don't have to unnecessarily extend its scope or copy it to some helper object. Just write your callback code in-place as an anonymous method and it can fully access and manipulate all local variables at the site where the anonymous method is defined (not where it's called!).

还有匿名方法的其他方面,最明显的事实是,他们是:匿名,但这是一个真正让他们为我点击我...

There are other aspects of anonymous methods, most obviously the fact that they are, well: anonymous, but this is the one that really made them go "click" for me...

这篇关于有人可以向我解释匿名方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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