You are here
Home > Programming > Debugging Lambda Expressions In Visual Studio 2015

Debugging Lambda Expressions In Visual Studio 2015

Debugging Lambda Expressions – Visual Studio 2015 has added the ability for developers to debug Lambda Expressions. This is a big improvement for me personally because I quite enjoy using Lambda Expressions. Now I can debug these Lambda Expressions and modify values to test different scenarios. Let’s take a look how we do it.

Debugging Lambda Expressions

To illustrate how easy it is to debug Lambda Expressions, I have created a simple method that reads order details into a list. As you can see this method returns nothing, but it is just to illustrate the use of Lambda Debugging. I have a Lambda Expression that returns only order items above a certain order value (OrderThreshold of 70). This is useful in a real world application where certain additional requirements are to be set for customers that make orders above a certain value.

From the returned list of orders we can now manipulate the expression in the Watch window. My threshold is 70, but let’s see if there are any orders above a higher threshold of 100 for example. We can now type the modified Lambda Expression directly into the Watch window. As you can see, the results are displayed nicely.

Debugging Lambda Expressions

Developers can now also do the same in the Immediate Window. Below we are returning the total value of all the orders contained in the order items list.

Debugging Lambda Expressions

Another nice tidbit is the ability to do the same thing from the pinned data tips. If you hover your cursor over the orderDetails variable, a tip will be displayed that shows you the returned items are 5.

Debugging Lambda Expressions

Clicking the push pin will now keep that data tip pinned and always available during your debugging session.

Debugging Lambda Expressions

If you right click this data tip, you can add a Lambda Expression there too.

Debugging Lambda Expressions

Here I want to get the total value of all the orders (same as we did in the Immediate Window). I can type the Lambda Expression and hit enter.

Debugging Lambda Expressions

The Expression is evaluated and the result is displayed in the data tip. This is a convenient solution for any developer several thousand lines deep in code. You are now free to explore, modify and correct faulty Lambda Expressions.

Debugging Lambda Expressions

While the example of the above order items might not have contained big values or contained many orders, consider the usefulness of this Lambda Debugging feature on results containing a couple of hundred records with order values ranging from a couple of thousand to a few million. The ability to debug Lambda Expressions cuts through all this data and allows developers to fine tune the expression to return the exact result they need.

For extra reading, see Support for debugging lambda expressions with Visual Studio 2015 by Patrick Nelson.

Happy debugging!

Dirk Strauss
Dirk is a Software Developer and Microsoft MVP from South Africa. He loves all things Technology and is slightly addicted to Twitter and Jimi Hendrix. Apart from writing code, he also enjoys writing human readable articles. "I love sharing knowledge and connecting with people from around the world. It's the diversity that makes life so beautiful." Dirk feels very strongly that pizza is simply not complete without Tabasco, that you can never have too much garlic, and that cooking the perfect steak is an art he has yet to master.

Similar Articles

Top