Validating with a debugger in C #

How to check the return value of this GetItems () function using a debugger? Do I have to create a local variable for the results in order to accomplish this?

foreach (string item in GetItems()) { // some code } private List<string> GetItems() { // return some list } 
+4
source share
3 answers

You can simply add it as a Watch and view the values ​​as expected.

Debugging: viewport

How to watch expression in debugger

+7
source

No, you can add a clock or quickwatch to GetItems () and you will see the result

+2
source

Could you:

 var items = GetItems(); foreach (var item in items) { // some code } 

Edit - in response to the comment, I agree with what the passerby says, but I prefer not to make inline method calls inside other constructs (method calls, if instructions, loops, etc.). For example, if you have a method call that looks like this:

 var result = SomeMethod(GetCode(), GetItems(), GetSomethingElse(), aVariable); 

It seems to me that it’s actually easier to read and debug if you do this:

 var code = GetCode(); var items = GetItems(); var somethingElse = GetSomethingElse(); var result = SomeMethod(code, items, somethingElse, aVariable); 

In the second case, you can more easily set a breakpoint on the method on which you really want to join, instead of switching to other method calls before entering the method that you want to debug. Only personal preference.

0
source

Source: https://habr.com/ru/post/1306956/


All Articles