Could you:
var items = GetItems(); foreach (var item in items) {
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.
source share