Tip: Using LINQ With Watches While Debugging in VS or VS Code

Posted by

Recently I came across a handy little feature in Visual Studio and Visual Studio Code that allows for fast analysis of debugging large data sets. For some background, when you debug a program and hit a break point, you can add watches to your variables to see what exactly is set. This is similar to just hovering over the variable to see what it’s data is. The problem is that this is effectively useless with large data sets as it’s hard to navigate what specific item you want to look at.

The handy feature I discovered was that you can type in basically anything into the Watch pane, and LINQ statements are supported. This means that you can look at a subset of data directly while debugging without having to write it into the program itself. For Visual Studio, just click in the empty row in the Watch pane and type your LINQ statement. VS Code requires you to click the plus sign on the right side of the watch pane, and an input will become available to add the expression to your list of watches.

Visual Studio Watch with LINQ Statement
Visual Studio Code Watch with LINQ Statement

I first realized you can use LINQ in watches while attempting to validate some business logic that was being executed against data that was being populated by API calls. While my example might not make it seem like it’s a very powerful feature, as you’re working with larger data sets it’s usefulness greatly increases.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.