我们可以在c#中命令调用委托函数吗? [英] Can we order the functions calling in delegate in c# ?

查看:99
本文介绍了我们可以在c#中命令调用委托函数吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我去采访,他们在那里问他想要在多播委托中调用委托函数

解决方案

当然可以。我的文章 动态方法调度程序 对此进行了解释。 。



在引用的章节4.2。返回值中,我演示了我的 MuticastDynamicMethodDispatcher 的一个用例当我必须逐个调用多播委托实例的每个元素委托实例时,泛型类。在我的代码中,我这样做是为了让用户可以声明一个自定义规则来累积返回值(参见第三段,最复杂的返回方法......),但你可以使用这种方法其他任何东西,例如,重新排序调用。



如果在调试器下使用我的库执行用例代码示例,您将看到该实现访问了多播委托实例的调用列表并遍历它以分别对每个元素进行单独调用。



用于理解内部结构的一些重要微妙方面的背景在委托实例中,您应该更好地阅读上一节, 动态方法调度程序; 4.1。 代表实例的性质



-SA

I went to interview ,There they ask me that he wanted to order the delegate functions calling in multicast delegate

解决方案

Yes, of course. This is explained in my article Dynamic Method Dispatcher.

In the referenced chapter "4.2. Return Values" I demonstrate one of the use cases of my MuticastDynamicMethodDispatcher generic class when I have to call each element delegate instance of the multicast delegate instance one by one. In my code, I do this for the purpose of giving the user the possibility to declare a custom rule for accumulating of the return values (see third paragraph, "The most sophisticated method of returning…"), but you can use this technique for anything else, for example, for reordering the calls.

If you execute the use-case code sample with my library under the debugger, you will see that implementation accesses the invocation list of the multicast delegate instance and traverse it to make individual invocation for each element, separately.

For understanding the background of some important delicate aspects of the internal structure of the delegate instances, you should better read the previous section, Dynamic Method Dispatcher; 4.1. On the Nature of Delegate Instance.

—SA


这篇关于我们可以在c#中命令调用委托函数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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