Lesson 25: Learning to move between codes when debugging C# Applications

We’ll teach you how to switch between codes when debugging C# applications in this lesson. I created a programme with the following code for this purpose:

namespace DebugTest
{
 class Program
 {
 static void Main(string[] args)
 {
 int a = 5;
 a = a * 2;
 a = a - 3;
 a = a * 6;
 Console.WriteLine(a);
21
 }
 }
}

The code in the example above performs various mathematical operations on a variable before printing the final result in the output. Slowly Insert a Breakpoint next to the first line where variable an is defined and quantified, as shown in the previous lesson.

The project should now be run. On the first line, you should run breakpoint. Moving the cursor over variable a will reveal its value. The variable a has the default value of the numeric variables, which is zero, because the code for that line has not yet been performed.

But let’s change the trend a bit.

From the Debug menu, select “over Step” or press the F10 key. In this case, the code line Next the program is executed and you can see by moving the mouse on the code that now the variable a has a value.

Press the F10 key again to move in the lines of code and run each line one by one and its variable value
Measure in that line, until you reach the end of the code.

The above example was very simple but at the same time practical, now we can enter the more advanced stages.

C

Note the following example:

namespace DebugTest
{
 class Program
 {
 static void Main(string[] args)
 {
22
 int a = 5;
 int b = 2;
 int result = MakeComplicatedCalculation(a, b);
 Console.WriteLine(result);
 }
 static int MakeComplicatedCalculation(int a, int b)
 {
 return a * b;
 }
 }
}

Put a breakpoint in the first line of the Main method and run it. Then, to move, hit the F10 key. Between programme lines and code execution, this is used.

As you can see, the software does not pay heed to the function call code. This is the Debugger assumption for the method mode Prediction. But, starting from the beginning, pick enter Step from the Debug menu, or hit the F11 shortcut key, when you reach the code line Call the Calculation Make ().

Press. At this point, the program enters the function call operation and scrolls the function body completely he does. So by pressing the F11 button, you can also check the execution of the program.
If you enter a function in the midst of a line, skip viewing the function’s continuation and move straight to the code. To return to the main programme, press F11 + shift or pick “out step” from the Debug menu. Press simultaneously.

In this situation, the software returns to the code after the function, allowing you to continue the code. After you want to call a function and then exit when it’s finished.

%d bloggers like this: