Debugging Lambda Expression in Visual Studio 2015 – Watch Windows, Immediate Windows and also in DataTips

Debugging Lambda Expression in Visual Studio 2015 – Watch Windows, Immediate Windows and also in DataTips

Debugging  Lambda expression is one of the coolest feature of Visual Studio 2015 and that’s bring lot of productivity among developers during debugging and release lot of pain. Using lambda expression is pretty often in code, mostly when we writes lots of LINQ statements. Priory to Visual Studio 2015, there was no direct and easy way, where we can debug, or inspect any lambda expression.

Now, Visual Studio 2015, support debug and run lambda express in Watch Windows, Immediate Window and in DataTips as well .

image

Let’s take a look at the following class Student

image

Following code block use the Student Class, and display a list of Students having marks greater than 40.

 

image

Now, consider you want to debug, manipulate some values with students.   Let’s have a look how to do it.

Immediate Window – Run, Debug & Inspect Lambda Expression

This is just awesome ! You will start getting all LINQ expression, extension method and write you own query too.

image

You can simply execute or debug the Lambda expression.

image

This save a lot of time and gave a lot of flexibility to developers.

Watch Window – Run, Debug & Inspect Lambda Expression

Watch windows is one of most commonly used debugging tool with Visual Studio. We generally used to explore the objects, values, properties and other nested objects as a tree structure.  We can do lot of stuff using Watch Window. Now we can do, debugging of Lambda Expression.

Must Read : Watch Window Tips and Tricks

Select the LINQ Expression and Click on Add To Watch

image

Now, Explore Your Data coming out of LINQ / Lambda

image

You can even write fresh statement.

image

And Of course, same things you can do it for Quick Watch Too.

image

DataTips – Run, Debug & Inspect Lambda Expression

DataTips is an advanced tooltip message that can be used for inspecting the objects or variables while debugging the application with in Visual Studio. Along with Watch Window and Immediate Window, DataTips also support debugging of Lambda Expression.

Step 1 : Add a DataTips during Debugging

image

 

Step 2:  Right Click on the DataTips and select “Add Expression” from the context menu.

Must Read : Adding New Expression in Visual Studio DataTips

image

Step 3 : Run and Execute Lambda Expression.

image

 

image

Hope this helps !

Abhijit Jana

Abhijit runs the Daily .NET Tips. He started this site with a vision to have a single knowledge base of .NET tips and tricks and share post that can quickly help any developers . He is a Former Microsoft ASP.NET MVP, CodeProject MVP, Mentor, Speaker, Author, Technology Evangelist and presently working as a .NET Consultant. He blogs at http://abhijitjana.net , you can follow him @AbhijitJana . He is the author of book Kinect for Windows SDK Programming Guide.