views:

73

answers:

2

Does VS 2008 provides a function that allows us to evaluate a method? I can view the property of an object via Watch window, but I also want to substitute parameters into a method and see the result.

Not sure whether VS 2008 supports this or not.

+2  A: 

You can evaluate methods pretty much anywhere - in the watch pane, QuickWatch window, and Immediate pane.

static string Foo(string x)
{
    return String.Format("Hello {0}.", x);
}

From the immediate window:

Foo("me");
"Hello me."
Michael Petrotta
A: 

To expand on Michael Petrotta's answer:

The immediate window is the best place for this. If you hit a breakpoint on some line of code like this:

var obj = GetObject("asd");
obj.CalculateSomething(5); // <--- breakpoint here.

You could type object.CalculateSomething(4) into the immediate window to evalulate it there. It doesn't have to be a static method, just valid code for the position in the source where your breakpoint is. Just be aware that if the method you call has side effects, they will persist. Everything you do in the immediate window runs in the app like normal code, so if you type obj = null in the immediate window, obj will be null when you continue debugging.

Jamie Penney