Debugging Basics and Reading Compiler Errors

Dot NET Programming 12 min min read Updated: Nov 16, 2026 Beginner
Debugging Basics and Reading Compiler Errors
Beginner Topic 5 of 5

Why Learn Debugging Early?

Everyone writes bugs. The difference between a beginner and a professional is how quickly they find them. The debugger lets you pause the program and look at every variable, so you stop guessing.

A Program with a Bug

csharp int[] scores = { 70, 85, 90 }; int total = 0; for (int i = 0; i <= scores.Length; i++) { total += scores[i]; } Console.WriteLine($"Average: {total / scores.Length}");
Result

The program crashes with IndexOutOfRangeException. Let us find out why using the debugger.

Step 1: Set a Breakpoint

Click in the gray margin left of the line total += scores[i]; (or press F9). A red dot appears. The program will pause there.

Step 2: Start Debugging

Press F5 (Start Debugging). The program runs until it reaches the red dot and stops.

Step 3: Look and Step

KeyNameWhat it does
F5ContinueRun until the next breakpoint
F10Step OverRun the current line and move to the next
F11Step IntoGo inside a method that this line calls
Shift + F11Step OutFinish the current method and return
Shift + F5StopEnd the debugging session

Hover over i and scores.Length to see their values. After several F5 presses you will see that i becomes 3, but the array only has indexes 0, 1 and 2.

The bug: The loop condition uses <=. It should be <. An array with 3 items has indexes 0, 1, 2.

Useful Debugger Windows

WindowUse it to
Locals / VariablesSee all variables in the current method
WatchType any expression, such as total / scores.Length, to track it
Call StackSee which methods called the current one
Breakpoint conditionsRight-click a breakpoint and pause only when i == 2

Printing Is Fine Too

csharp Console.WriteLine($"i = {i}, total = {total}"); System.Diagnostics.Debug.WriteLine("Only shown while debugging");

Fast Feedback with dotnet watch

bash dotnet watch

The program re-runs automatically every time you save. Great for learning.

Common Compiler Errors

ErrorMeaningFix
CS1002: ; expectedMissing semicolonAdd ; at the end of the line
CS0103: name does not existTypo or variable out of scopeCheck spelling and where it was declared
CS0246: type or namespace not foundMissing using or packageAdd the using line or dotnet add package
CS0029: cannot convert typeWrong type assignedConvert, for example int.Parse(text)
CS8602: possible null referenceNullable warningCheck for null before using the value
CS0165: use of unassigned variableVariable not given a valueInitialize it, for example int x = 0;
How to read errors: Always read the first error. Later errors are often just side effects of the first one. Click it to jump to the exact line.

Conclusion

Set a breakpoint, step through and inspect variables instead of guessing. Learn to read the first compiler error carefully.

Quick Summary: F9 breakpoint, F5 run, F10 step over, F11 step into, Watch window to check values.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators