Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
Use the Immediate window to debug and evaluate expressions, execute statements, and print variable values. The Immediate window evaluates expressions by building and using the currently selected project.
To display the Immediate window, open a project for editing, and then choose Debug > Windows > Immediate or press Ctrl+Alt+I. You can also enter Debug.Immediate in the Command window.
The Immediate window supports IntelliSense.
Display the values of variables
The Immediate window is particularly useful when you're debugging an app. For example, to check the value of a variable
varA, you can use the Print command:
The question mark (?) is an alias for
Debug.Print, so this command can also be written:
Both versions of this command return the value of the variable
To issue a Visual Studio command in the Immediate window, you must preface the command with a greater than sign (>). To enter multiple commands, switch to the Command window.
Design-time expression evaluation
You can use the Immediate window to execute a function or subroutine at design time.
Execute a function at design time
Copy the following code into a Visual Basic console app:
Module Module1 Sub Main() MyFunction(5) End Sub Function MyFunction(ByVal input as Integer) As Integer Return input * 2 End Function End Module
On the Debug menu, choose Windows > Immediate.
?MyFunction(2)in the Immediate window and press Enter.
The Immediate window runs
If the function or subroutine contains a breakpoint, Visual Studio breaks execution at the appropriate point. You can then use the debugger windows to examine your program state. For more information, see Walkthrough: Debugging at Design Time.
You can't use design-time expression evaluation in project types that require starting up an execution environment, including Visual Studio Tools for Office projects, web projects, Smart Device projects, and SQL projects.
Design-time expression evaluation in multi-project solutions
When establishing the context for design-time expression evaluation, Visual Studio references the currently selected project in Solution Explorer. If no project is selected in Solution Explorer, Visual Studio attempts to evaluate the function against the startup project. If the function cannot be evaluated in the current context, you'll receive an error message. If you're attempting to evaluate a function in a project that's not the startup project for the solution and you receive an error, try selecting the project in Solution Explorer and attempt the evaluation again.
Enter the greater than sign (>) when issuing Visual Studio commands in the Immediate window. Use the Up arrow and Down arrow keys to scroll through your previously used commands.
|Evaluate an expression.||Preface the expression with a question mark (?).||
|Temporarily enter Command mode while in Immediate mode (to execute a single command).||Enter the command, prefacing it with a greater than sign (>).||
|Switch to the Command window.||Enter
|Switch back to the Immediate window.||Enter
When you click on any previous line in the Immediate window, you shift automatically into Mark mode. This allows you to select, edit, and copy the text of previous commands as you would in any text editor, and paste them into the current line.
The following example shows four expressions and their result in the Immediate window for a Visual Basic project.
j = 2 Expression has been evaluated and has no value ? j 2 j = DateTime.Now.Day Expression has been evaluated and has no value ? j 26
First-chance exception notifications
In some settings configurations, first-chance exception notifications are displayed in the Immediate window.
Toggle first-chance exception notifications in the Immediate window
On the View menu, click Other Windows, and click Output.
Right-click on the text area of the Output window, and then select or deselect Exception Messages.