1.4 Debugging

You’ve probably heard about debugging. But what it is and how to apply it in C#?

Debugging is an integral part of development during which bugs (errors) are discovered, localized and fixed.

With debugging we can:

  • Find out the current value of variables;
  • Find out which path the program was running on;

There are many different tools for debugging program, but we will consider the most basic which you cannot do without in any project — Breakpoint.

Breakpoint temporarily stops the application at the line on which breakpoint located. All lines of code up to the breakpoint will be executed, but the line on which the breakpoint is set will not be executed.

Let’s see the breakpoint in action and take the project from the previous lesson.

There are two ways to set breakpoint:

  1. Click on the desired code line, then press F9;
  2. Click the mouse opposite the required line

The result will be the same — red dot:

Okay, we can launch a project (F5 or green arrow in the toolbar) and don’t forget to launch in Debug mode, because Visual Studio uses two built-in build configurations — Debug and Release.

In debug mode the program compiles without optimization and have all necessary information for debugging.

Now the program has stopped at a breakpoint and is waiting for our actions. To continue execution press F10 or Step over in toolbar (I prefer use F10).

Program waits until you type a name in the console and press enter,after which the program execution stops on the next line.

When hovering a variable we can see its value and change it dynamically by clicking and typing a new value.

Type F10 one more time and you will see result:

So we looked at the most primitive example with breakpoint. If you need go inside of some method (we will see it in the next section, when will teach a methods), enter F11 or Step Into in toolbar.

If you need to leave from debugging mode enter Shift + F11 or Step Out.

One more interesting thing, you can add Breakpoint Conditions

And here you can configure your breakpoint as you want.

Now you know how to debug and catch bugs 🙂

Contents

Previous article -> 1.3 First Program and Install VS 2022

Next article -> 1.5 .NET CLI

Join to our community in Telegram — https://t.me/itifico

If you want to support me, you can buy me a cup of coffee and I will drink it when I write the next article :)

Donations list:

  1. Dinesh Chintalapudi — 3$
  2. Unknown — 5$

--

--

--

Full Stack Developer who is inspired by new technologies

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

GitOps: Modern Ops For Kubernetes

GitOps Modern Ops For Kubernetes

7 Simple Steps to host your website — for free!

Blog 17 Computational Art and Object Oriented Ontology: What its like to be a thing

Casio Calculator

Casio calculator fx

Phrases That You Need to Understand When Talking to a Drupal Developer: Node

JVM 101: Garbage Collection and Heap (Part 2)

A Quick Introduction to the Programming Terms: Python Complete Course — Part 1

A dummy image for better reading and navigation.

Compilation process in C

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Stasoz

Stasoz

Full Stack Developer who is inspired by new technologies

More from Medium

1.2 Evolution of C#

What are Middlewares and How They are Used in .NET

How to write a very fast regex in C #. Best Practice