11

Resharper 5 can convert my foreachloops to Linq queries. Which I like. But linq is way way way harder to debug than a foreachloop.

When I convert my foreach statement to a linq query, I don't see any option to go back the other way.

Does any one know how to do this? Is it even possible?

Vaccano
  • 78,325
  • 149
  • 468
  • 850
  • 1
    Sounds like it would be worthwhile for Resharper to implement this. – Jim G. Jul 06 '10 at 16:28
  • @ Jangwenyi - I can undo the change if I happen to have just done it. But I am talking about if I just found a linq query that is throwing an exception. I was hoping that my query could be converted back to a foreach even though I converted it to a linq query a while ago. – Vaccano Jul 06 '10 at 16:56
  • 1
    +1, LINQ looks great but it is miles harder to debug. I've got exactly the same issue, used resharper to convert and now I'm going to have to manually convert back to foreach just so I can tell what's going on. Lesson learned - leave everything as foreach. – Blingers Nov 30 '17 at 09:50

2 Answers2

6

We are working on LINQ2Foreach (and some other) functionality for ReSharper vNext

Ilya Ryzhenkov
  • 11,782
  • 1
  • 40
  • 50
  • 7
    It's been a few years. Is it in the product now? Might be a good time to update this answer. – Vimes Mar 28 '13 at 20:53
2

I do not believe this is possible. Certainly, it's not listed in the examples of Quick Fixes, where loop-to-LINQ-expression is shown.

What you should be able to do is use the Context Action 'Convert LINQ to methods chain' to go from the 'fluent' style to the 'methods' style, and then selectively use 'Introduce variable' to pull the expression to pieces.

AakashM
  • 62,551
  • 17
  • 151
  • 186