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 ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The premise is wrong; it works fine:
That is a multicast delegate with a non-void result, working fine. You can see from the console that both parts executed. The result of the last item is the one returned. We can demonstrate that this is a true multicast delegate:
and it will write “I’m multicast” even after just the first line (when there is only a single method listed).
If you need more control over individual results, then use
GetInvocationList():which allows you to see each individual result.
In IL terminology:
which is to say:
Func<T>inherits fromMulticastDelegate. Basically, to all intents and purposes, all delegates in .NET are multicast delegates. You might be able to get a non-multicast delegate in managed C++, I don’t know. But certainly not from C#.