How to execute LINQ and / or foreach in an Immediate window in VS 2013?

The instant window is a fantastic tool for checking the current state during the debugging process. I found out that using the question mark can do a little more, as shown in this post .

However, I still don't know how to execute LINQ queries ( including lambda expressions). I also could not execute the foreach statement.

When performing the following statements:

?(things.Select(thing=>thing.Id);) ?(foreach(var thing in things);) 

I get the following errors:

Expression cannot contain lambda expressions
Invalid expression term 'foreach'

(How) can I execute them in the Immediate window?

There is also a tool in VS Gallery , but he said that it only works for VS05 and VS08, which most programmers left behind looong time ago. I am looking for something that applies to VS13 and / or VS15.

+8
c # lambda linq visual-studio immediate-window
source share
3 answers

In accordance with the new features available in visual studio 2015, lambdas debugging support is now available in the clock / immediate access window:

Windows Debugger Lambda Expressions

Now you can use lambda expressions in Watch, Immediate and other debugger windows in C # and Visual Basic.

A source:

RTM version of Visual Studio 2015

+7
source share

In VS2015, you can use lambda expressions in the viewport and in the immediate window.

Just add a clock or type in the nearest window (while debugging and things are in the area):

 things.Select(thing => thing.Id); 

and you will get a list of results.

Here is a blog about this

+3
source share

Unfortunately, it is not possible to use lambda either from a window or from a viewport. The technical reason for this is the likelihood that linq queries are usually converted to normal expressions and that this requires a full compilation step instead of the cheating used by these two windows.

If you did not know that the thing=>thing.Id is a lambda expression.

0
source share

All Articles