Stepping through the code in C3

In this section, we will take action through your code, which is another important part of debugging. For the purpose, I wrote this simple application:


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

It only adds variable "A" several times and outputs the end result, try to keep the breakpoint, as described in the previous chapter, where one (and declared) is used on the first line, now run the application. The execution has been stopped and you can hover your mouse over one, to make sure that what we learned in the previous chapter is really true: only the default value of the variable is because this code value (5 In the case), has not been executed yet, but we change it. From the debug menu, select the "Step Over" option, or even better, use the keyboard shortcut F10. The execution will now proceed to the next relevant line and if you move your mouse over a variable, you will notice that there is value in it . Try again, and you will see the price changes according to the rows that are being executed once you reach the end

Okay, so it was very basic, but it is also very useful, because you will understand that once you start writing more complex code in this example, the flow of code was very easy because we were at a function , But what if your code spreads on many sections and / or works? Try this example:


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

        static int MakeComplicatedCalculation(int a, int b)
        {
            return a * b;
        }
    }
}

Place a breakpoint on the first line of the main method and run the application. Now use the "step over" function to move forward from each line, as you will see, this function transmits the call without any notice - from the beginning, how debugging works from now, try again , And once you reach the line with MakeComplicatedCalculation (), select debug -> in the step, or use the keyboard shortcut F11 debugger now the first possible function in the call in the step, Can also take steps through the medium. As you can imagine, when entering the function call you get the permission to take action through the complex blocks of code, you get only interests

If you step into the function and then feel that you will not come back in the previous context, then you use a very logically named option named "Step Out" (keyboard shortcut Shift + F11) from the debug menu Are there. This will return you to your previous context, which clearly means that you want you to find the function you call, and then find your way using the step-out option.