How are return values from a delegate handled?

Published 27 May 04 03:50 PM

Q: How are multiple return values from a delegate handled?

In C#, it's possible to write a delegate such as:

delegate double GetResult(params double p);

If there is more than one method on this delegate, there are multiple return values.

A: In this situation, the return value is the value that is returned from the last delegate.

If you want more control on this, you can call GetInvocationList() on the delegate, which will allow you to call each method individually, and process the double values appropriately.

[Author: Eric Gunnerson]

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Joku said on May 28, 2004 1:45 AM:
> If there is more than one method on this delegate

I have to say this is a bit vague on me, do you mean that there are multiple methods "matching the signature" of that GetResult delegate?
# Joku said on May 28, 2004 1:48 AM:
Ahh.. I get what you mean now lol :) Need some coffee Doh
# Eyal said on June 26, 2004 10:06 PM:
private void StartEvent_Click(object sender, System.EventArgs e)

{

if( StartEvent != null ){

foreach(DemoEventHandler dlg in StartEvent.GetInvocationList()){

try{

if( (bool)dlg.DynamicInvoke(new object[]{this,e}) ){

......

} else

}

......

{

}

catch( ApplicationException ex ){

...

}

}

}

}

# Eyal -Async said on June 26, 2004 10:07 PM:
public delegate bool DemoEventHandler(object sender, EventArgs e);

public event DemoEventHandler StartEvent;



private void StartEvent_Click(object sender, System.EventArgs e)

{

if( StartEvent != null ){

foreach(DemoEventHandler dlg in StartEvent.GetInvocationList()){

try{

// Invoke Async call

dlg.BeginInvoke(this,e,new AsyncCallback(CallBack),null );

}

catch( ApplicationException ex ){

???? ?? ????? ????? ??? ??????? ????? ?? ?????...

}

}

}

}





private void CallBack( IAsyncResult ar )

{

AsyncResult aResult = (AsyncResult)ar;

DemoEventHandler dlg = (DemoEventHandler)aResult.AsyncDelegate;



// Complete the asynchronous call.

if( dlg.EndInvoke( ar ) )

????? ?????? ?????? ??????......

else

????? ?????? ?? ?????? ??????......

}

Leave a Comment

(required) 
(optional)
(required) 

  
Enter Code Here: Required

This Blog

Syndication

Page view tracker