Friday, December 4, 2015

Debugging return values in C#

Hi,

I found an extremly helpful feature in Visual Studio 2013: showing the value which is returned by a function.
Example:


1
2
3
4
public bool CheckExists(string itemId)
{
   return ItemList.Exists(item => item.ItemId == itemId);
} // <- breakpoint

With the debugger it is hard to find whether the itemId is or is not in the list (if the list has thousands of entries), BUT as shown in the link it is possible to get this value through the "Autos" window or the immediate window in visual studio while having a breakpoint on the "}" in line 4. The good news is that it even works with "$ReturnValue" in the watch window, but in contrary it seems not to work properly for any use case (with all above introduced solutions). I'm pretty sure that this is reasonable if we have a look on the disassambly, but that is out of scope here.
kind regards,
Daniel

No comments: