This article is currently in the process of being translated into Hungarian (~27% done).
Breakpoints
A hibakeresés során a legelső dolog, amit ismernünk kell, a breakpoint. Tényleg pontosan azt teszi, amit a név sugall – kijelöl egy pontot a programban, ahol a végrehajtás szünetel (és nem, nem fogja feltörni a programot, nem kell aggódni). A breakpoint beillesztése a Visual Studio vagy az Express verziókba egy egyszerű kattintás a bal egérgombbal a baloldali szürke oldalsávban. Ha rákattintunk, jutalomként fényes pirospontot kapunk – ez a pont jelöli azt a helyet, ahol a hibakereső megáll, amikor végrehajtja az alkalmazást. Jobb, ha meg is nézzük, és a hatás megtekintéséhez a következő programrészletet fogjuk használni:
namespace DebugTest
{
class Program
{
static void Main(string[] args)
{
int a = 5, b = 8, c = 233;
int d = a + c - b;
Console.WriteLine(d);
}
}
}
Now, can you predict the result just from looking at the code? Probably, and if not, you could just get out the old calculator and do the math, but that's not really the point. Just imagine the amount of code being much bigger, and let's debug the thing! Place a breakpoint by clicking in the left gutter - your IDE should now look something like this:
Okay, you're ready to start your first debugging session. As soon as you have placed the breakpoint, you can just run your application like you normally would - from the menu, the toolbar or by pressing F5. What happens now is that the application is executed just like normal, but as soon as a line with a breakpoint is reached, the execution is stopped right before that line would be executed. In this case, it means that the variables a, b and c will have a value, but d will only have it's default value (which is 0 for an integer), since it won't be set before the line with the breakpoint has been evaluated. Now, here comes the cool part - try hovering your mouse over the different variables - the IDE will tell you what they contain. As mentioned, the d variable will have it's default value, but let's change that, by moving forward in the execution. In the next chapter, I will show you how to navigate around your code, while it's being executed.