Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I know this is an old post, but just in case anyone comes across it, it is certainly possible to do this. You declare your own delegate that returns a value, then base the event off this new delegate. Here is an example:</p> <p>In the event declarer / publisher:</p> <pre><code>// the delegate public delegate string ReturnStringEventHandler(object sender, EventArgs args); // the event public event ReturnStringEventHandler StringReturnEvent; // raise the event protected void OnStringReturnEvent(EventArgs e) { if (StringReturnEvent != null) // make sure at least one subscriber // note the event is returning a string string myString = StringReturnEvent(this, e); } </code></pre> <p>In the event subscriber:</p> <pre><code>// Subscribe to event, probably in class constructor / initializer method StringReturnEvent += HandleStringReturnEvent; // Handle event, return data private string HandleStringReturnEvent(object sender, EventArgs e) { return "a string to return"; } </code></pre> <p>.NET provides an example of this in the AssemblyResolve event, which uses the ResolveEventHandler delegate to return data, in this case a reference to the desired Assembly. <a href="http://msdn.microsoft.com/en-us/library/system.appdomain.assemblyresolve.aspx" rel="noreferrer">MSDN Article on AssemblyResolve event</a></p> <p>I have personally used both the AssemblyResolve event and the custom delegate technique to return data from an event, and they both work as expected on Visual Studio 2010.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload