Debugging in .NET apps using Visual Studio Part 1
Tags: visualstudio, dotnet, debug, csharp
Published: 2023-01-13 18:30:32

I’m getting back from cycling right now and I think about the relationship between car and bicycle in debugging, sounds weird but very interesting to me.
I am cycling, and I can see all the detail on my way until I arrived at my destination but when I am driving a car, I can’t see the true detail of my ways like asphalt surface or plants growing in between rocks and asphalt. In debugging we set behind the bicycle and cycle step by step in the code and when we are in release mode, we don’t want to see much detail in our way just two things are important to us, first is it must be working and second is we must arrive to our destination. So, let’s get to know about some great tools in our cycling that makes our way smoother.

## 1. Debugging mode
On the top of the visual studio, we have 2 options for choosing our journey mode. The first option is Debug mode and by default, it is selected. In debug mode, we have many options to track our code and see all the details step by step.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/008m5jpg5pju82vuq8su.png)

## 2. Release mode
The second option is releasing mode, this mode is designed to test our app in the final version and virtualize our customers' environments.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p9l0fy0o87etnr6weloj.png)

## 3. Breakpoints
Breakpoints are the signs of what we want to check after running the program.
They can be easy use by clicking next to the line number in visual studio.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h39zmvv2ffq3g8yclfz1.png)

After the breakpoint is set, when we run our program in debug mode, we can see the program stop in the line we want to see the special behavior or track the code.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ssy9gdz7p4c4rh65grml.png)

When the debugger arrived at our breakpoint the line color is changed to yellow and which means that the line doesn’t execute right now but with the F10 key you can execute the code. We talk about the executing code after hitting breakpoints later so don’t worry about this.
### Change the behavior of executed line
We can easily change our line executer (yellow arrow on the left side of code number) behavior to run what we want in the visual studio.
The first way is you can simply drag and drop the executed line at which code line you want to just execute that line.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/du64sevjsyvdk4zy6jqp.png)

Then you can press F10 to execute the ‘’c” variable and then you can see the debugger ignore the “a” and “b” variables and their default value are 0.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uvwoohx5zpuw46pm164k.png)

So that’s the easy way but let’s think about whether we have a 1M line, does it works in the big solutions? The answer is no but don’t worry because the visual studio developer team developed this great feature. So, let’s learn the second way for doing this thing.
Are you ready? Just simply right clicks and chose the next statement option for going to that exact line and executing that.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rjcif854ee804jdcgaz9.png)

Alright but if we want to run the previous line until that execution run, what can we do? Do we have any solutions? Happy to answer that question and that is yes!
Like the previous situation we have two ways to do that, first is just to hove a mouse in the specific line we want to execute with the previous code lines and select the green run (play) button.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0xxspeszta032l1dai1w.png)

The second way is simply to right-click on the execute line you want and then just chose the run to cursor option.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vmwxo2xllv9jb3xo90qo.png)

In the next part of this series of articles we read about how to step into our code (like F10 and F11) and then we go deeply into the breakpoints feature like condition breakpoints.
I hope you like this collection of my articles and enjoy that.