0

In debug mode, I can see what returned from method by moving mouse pointer to "name" variable;

public string GetUserName(int id)
{
    string name = UserService.GetUserName(id);
    return name;
}

But I don't want to create a variable to just to see what inside it...

So what is the proper way to debug one line returned method like;

public string GetUserName(int id)
{
    return UserService.GetUserName(id);
}

*Notes

  • I don't want to use F11 to get inside of GetUserName method.
  • I don't want to use immediate window.
i3arnon
  • 113,022
  • 33
  • 324
  • 344
Lost_In_Library
  • 3,265
  • 6
  • 38
  • 70

2 Answers2

2

Visual Studio's newest version, 2013, supports it right out of the box. In earlier versions, there's not much to do than to create a dummy variable and test it.

You can copy the whole method UserService.GetUserName(id) to the watch window and it will give you a result. If the method is deterministic then the result in the watch window will be the same one as in your code.

i3arnon
  • 113,022
  • 33
  • 324
  • 344
1

You can either use QuickWatch, or add a Watch to the watch window.

Select the whole expression (without "return" of course), then right click to use either of the two above mentioned tools.

Cheers

Luc Morin
  • 5,302
  • 20
  • 39