Debugging code using LINQ and Lambda Expressions in VS 2015

 In this post I will share how easy we can debug LINQ and Lambda expressions in Visual Studio 2015. Sometimes, it is difficult to see larger list in debugging mode. With this feature of VS 2015 we can filter list using LINQ or Lambda expression using Immediate or Watch windows.

Let’s take a quick example of a console application that calls up a method named GetPersons that returns the list of persons.

Below is the class that call GetPersons method which returns a list of 4 persons

1

Now let’s put a break point at the end of Main method

2

You can see that GetPersons() returned the list which you can even see it in the Immediate or Watch windows in earlier versions of Visual Studio as well. But if you want to filter records using some LINQ or Lambda expression, it is not possible in previous versions.

3

Below is the snap shot taken from VS 2013 that shows this error “Expression cannot contain lambda expressions”

4

If you run the same expression in Visual Studio 2015. You will see the result like this

5

You can also use Immediate Window to filter records as below

6

Hope this helps!