MSDN Documentation – Visual Studio Debugging

Overview

Visual Studio provides a powerful set of debugging tools that let you inspect, control, and diagnose your code at runtime. Use breakpoints, watch expressions, and the Immediate window to understand program flow and state.

Breakpoints

Set breakpoints by clicking the gray margin next to a line of code or pressing F9. Right‑click a breakpoint for additional options such as conditions, hit counts, and filters.

// Example: Conditional breakpoint
if (value > 100)
{
    // Execution will break here when condition is true
}

Watch Window

Add variables or expressions to the Watch window to monitor their values as you step through code. Use Ctrl+D, W to open it.

// Watch these expressions
myObject.Count
Math.Sqrt(total)
userInput?.Length

Immediate Window

Execute code statements on the fly while debugging. Open with Ctrl+Alt+I.

// Example commands
? myObject.Count
myList.Add(42)
Debug.Assert(value != null)

Call Stack

The Call Stack pane shows the chain of method calls that led to the current breakpoint. Double‑click a frame to navigate to its source.

Tips & Tricks

  • Use Ctrl+F5 to start without debugging when you only need to run the app.
  • Enable IntelliTrace for historical debugging (Enterprise edition).
  • Configure Exception Settings to break on specific exceptions.
  • Utilize Debugging Visualizers for complex objects.