gpt4 book ai didi

c# - Delegate 怎么调用很多方法呢?

转载 作者:太空宇宙 更新时间:2023-11-03 11:57:29 24 4
gpt4 key购买 nike

委托(delegate)是对方法的引用:1 个地址到 1 个内存单元,即我们的方法。那么当我将多个方法链接到一个委托(delegate)时,这个地址如何调用多个方法呢?

最佳答案

Delegate is a reference to a method: 1 address to 1 memory cell

不一定是。委托(delegate)可以通过 + 组合,+Delegate.Combine 的简写。调用复合委托(delegate)将依次涉及每个目标。

所以:

SomeDelegate x = obj.Whatever;
SomeDelegate y = arg => other.SomeMethod(arg, capturedLocal);
SomeDelegate z = x + y;
z(42);

关于c# - Delegate 怎么调用很多方法呢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58935817/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com