Debugging compiled C# uses IDE breakpoints, watches, and call stacks—like gdb for C++ but integrated with Roslyn symbols. Build Debug configurations include symbols; Release optimizes away easy stepping.
Practices
- Run
dotnet build -c Debugduring development - Set breakpoints on lines; inspect locals and exception details
- Use
dotnet testto reproduce failures with assertions - Enable analyzers and nullable warnings early—cheaper than runtime-only bugs
Logging vs debugging
Structured logging (ILogger) complements breakpoints in production—this lesson focuses on interactive debugging locally.
Important interview questions and answers
- Q: Debug vs Release?
A: Debug includes symbols and fewer optimizations; Release is faster but harder to step through. - Q: Conditional breakpoints?
A: Break only when an expression is true—essential for loops with many iterations.
Self-check
- Which build configuration includes full debug symbols?
- What CLI command runs automated tests?
Tip: Build Debug locally for symbols—breakpoints map to source lines; Release strips debug info for production.
Interview prep
- Debug vs Release?
Debug includes symbols and disables optimizations; Release optimizes for production and strips debug info.
- Conditional breakpoints?
Break only when an expression is true—speeds up debugging loops in large datasets.