multicastdelegate

Multicast Delegates must have a return type of void. Why?

风格不统一 提交于 2019-11-30 04:19:20
问题 Multicast Delegates must have a return type of void Otherwise it will throw an exception. I want to know whats the reason behind it, what if multiple methods could have a same return type as of a delegate ? 回答1: The premise is wrong; it works fine: Func<int> func = delegate { Console.WriteLine("first part"); return 5; }; func += delegate { Console.WriteLine("second part"); return 7; }; int result = func(); That is a multicast delegate with a non-void result, working fine. You can see from the

Swift Language Multicast Delegate

拈花ヽ惹草 提交于 2019-11-30 03:58:23
I am trying to implement the multicast delegate functionality in Swift. In Objective C, we have this excellent implementation https://github.com/robbiehanson/XMPPFramework/blob/master/Utilities/GCDMulticastDelegate.m And I have just created this basic functionality: protocol MyProtocol : class{ func testString()-> String; } class MulticastDelegateNode <T:AnyObject> { weak var delegate : T? init(object : T){ self.delegate = object; } } class MulticastDelegate <T:AnyObject> { var delegates = Array<MulticastDelegateNode<T>>() func addDelegate(delegate : T){ var newNode = MulticastDelegateNode

Use of multicast in C# multicast delegates

若如初见. 提交于 2019-11-29 14:29:27
When is it useful to have multicast delegates over singlecast delegates? I use delegates a lot, mainly coupled with C# lambdas, but I've never felt the urge to use the multicast aspect of C# delegates, ie I've never wanted to combine multiple delegates together in a single delegate. I'm therefore very curious in what sort of situation multicast delegates are useful - I can only think of examples in which you can easily implement the functionality some other way, by, say, chaining the delegates or putting them in a list. In particular, Eric Lippert's answer here gives the impression even the C#

Is there a Delegate which isn't a MulticastDelegate in C#?

丶灬走出姿态 提交于 2019-11-29 06:49:29
I think the answer is NO? If there isn't, why do we have separated Delegate and MulticastDelegate classes? Maybe it's again because of "some other .NET languages"? EDIT: I thought this was part of ECMA 335, but I can't see it in there anywhere. You can't create such a delegate type in C#, but you can in IL: .class public auto ansi sealed Foo extends [mscorlib]System.Delegate { // Body as normal } The C# compiler has no problems using such a delegate: using System; class Test { static void Main() { Foo f = x => Console.WriteLine(x); f("hello"); } } But the CLR does when it tries to load it:

Swift Language Multicast Delegate

流过昼夜 提交于 2019-11-29 01:38:49
问题 I am trying to implement the multicast delegate functionality in Swift. In Objective C, we have this excellent implementation https://github.com/robbiehanson/XMPPFramework/blob/master/Utilities/GCDMulticastDelegate.m And I have just created this basic functionality: protocol MyProtocol : class{ func testString()-> String; } class MulticastDelegateNode <T:AnyObject> { weak var delegate : T? init(object : T){ self.delegate = object; } } class MulticastDelegate <T:AnyObject> { var delegates =

Use of multicast in C# multicast delegates

社会主义新天地 提交于 2019-11-28 08:34:46
问题 When is it useful to have multicast delegates over singlecast delegates? I use delegates a lot, mainly coupled with C# lambdas, but I've never felt the urge to use the multicast aspect of C# delegates, ie I've never wanted to combine multiple delegates together in a single delegate. I'm therefore very curious in what sort of situation multicast delegates are useful - I can only think of examples in which you can easily implement the functionality some other way, by, say, chaining the

Simple Delegate (delegate) vs. Multicast delegates

时光怂恿深爱的人放手 提交于 2019-11-27 06:26:50
I have gone through many articles but I am still not clear about the difference between the normal delegates that we usually create and multicast delegates. public delegate void MyMethodHandler(object sender); MyMethodHandler handler = new MyMethodHandler(Method1); handler += Method2; handler(someObject); The above delegate MyMethodHandler will call these two methods. Now where does multicast delegates come in. I have read that they can call multiple methods but I am afraid that my basic understanding about delegates is not correct. This article explains it pretty well: delegate void Del

Simple Delegate (delegate) vs. Multicast delegates

本秂侑毒 提交于 2019-11-26 11:59:49
问题 I have gone through many articles but I am still not clear about the difference between the normal delegates that we usually create and multicast delegates. public delegate void MyMethodHandler(object sender); MyMethodHandler handler = new MyMethodHandler(Method1); handler += Method2; handler(someObject); The above delegate MyMethodHandler will call these two methods. Now where does multicast delegates come in. I have read that they can call multiple methods but I am afraid that my basic