What method is a delegate assigned to

Go To StackoverFlow.com

1

This is the definitions I have in the

private SavePreferenceCallback savePreferenceHandler;

public SavePreferenceCallback SavePreferenceHandler
{
  get
  {
    return savePreferenceHandler;
  }
  set
  {
    savePreferenceHandler = value;
  }
}

and then in debugging the code when I come to a line that is this:

savePreferenceHandler();

I don't know how to go further and what to look at? what method is it running?

2012-04-05 20:03
by Bohn


1

If you want to know what method will be called you can mouse over the variable savePreferenceHandler, and the debugger will show you what method is assigned.

enter image description here

You also can put a breakpoint in your property setter to see what method is assigned.

Lastly, you could use F11 and step into the method as it is invoked.

2012-04-05 20:05
by payo
Thanks for the picture. Helped a lot - Bohn 2012-04-05 20:14


5

Press F11 to step into the code and you'll find out, basically. Or you could always examine the value of savePreferenceHandler to see the method (or methods) it represents.

Side-node: if you're using C# 3 or above, you can make that property considerably simpler:

public SavePreferenceCallBack SavePreferenceHandler { get; set; }

You might also consider making it an event instead.

2012-04-05 20:04
by Jon Skeet
F11 or F12?... - Bohn 2012-04-05 20:07
F12 is 'go to definition', would only show the OP where he declared the savePreferenceHandler variable - payo 2012-04-05 20:07
Ads