我在哪里使用代表? [英] Where do I use delegates?

查看:169
本文介绍了我在哪里使用代表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有哪些真实世界的地方要求代表?我很好奇这种方法是最好的解决方案的情况或模式。不需要代码。

What are some real world places that call for delegates? I'm curious what situations or patterns are present where this method is the best solution. No code required.

推荐答案


代理是定义一种特定类型的方法的命名类型。正如一个类定义一样,它定义了给定类型的对象的所有成员,委托人为它定义的方法类型定出了方法签名。

A delegate is a named type that defines a particular kind of method. Just as a class definition lays out all the members for the given kind of object it defines, the delegate lays out the method signature for the kind of method it defines.

基于此语句,委托是一个函数指针,它定义了该函数的外观。

Based on this statement, a delegate is a function pointer and it defines what that function looks like.

一个真正的应用程序的一个很好的例子的代表是谓词。在链接的示例中,您会注意到 Array.Find 需要该数组搜索然后一个谓词来处理要查找的标准。在这种情况下,它会传递与Predicate签名相匹配的ProductGT10方法。

A great example for a real world application of a delegate is the Predicate. In the example from the link, you will notice that Array.Find takes the array to search and then a predicate to handle the criteria of what to find. In this case it passes a method ProductGT10 which matches the Predicate signature.

这篇关于我在哪里使用代表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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