From the course: Complete Guide to .NET LINQ: Querying Collections, Databases, and Markup

How to debug code in LINQPad

- Now let's use our newfound knowledge of how to use the File Explorer to open the debug sample. So here you can see all the folders. I'm in this section, LinqToObjects. I'm in the LinqPadTour. So I'd go here, I'm in the Tour folder and I'm looking at the Debug sample. And this is how it's going to work going forward. There's hundreds of sample files in here for this course. If you just look at the lower left, you can see the folder I'm using at the time. And if you look at the top, you can see the file that I'm working with. I want to debug this. Right now I'll just run it and see my results. There are no results. Can you see why? If you look at line six, I wrote console on the right line, but I did not put any data. So we're going to fix that, but first let's debug it. So I'll go up here to line three and click here to put a break point in the margin and then I can execute the query. So what'll happen is LinqPad will run the code and attach a debugger. And just like in Visual Studio, you'll see the yellow highlight on the line of code that's going to run. I also get a Threads window, a Locals window, and a Watch window. I can see the status that I'm paused. Over here on the right side, I can see that there is a debugger attached. I can also see the Call Stack and I'll look at the Locals window and I can see that my variable X is currently has the value of zero and that the data type is an Int32. Next I will step through my code. So I can do that by going to the Debug menu and choosing Step Into or Step Over or Step Out. F11 to Step Into, so that'll run the next line of code. Now I see the value's been set to nine. Do it again. Now the value's 14. And of course now I need to, can I modify the code while it's running? So I'll type in a new value here, or the X value there, I should say. And then we'll Step Into. It says, oh, query was modified, would you like to restart? That sounds good. And this time I'll move the execution pointer. Just drag it down here to line six and then continue. So that shows you how to use the Debugger. It's very similar to how the debugger works in Visual Studio.

Contents