This web site uses cookies. By using the site you accept the cookie policy.This message is for compliance with the UK ICO law.

VS 2003+

Visual Studio Immediate Window

Visual Studio's immediate window allows interaction with variables during the execution of a program in debug mode. The window allows variable values to be inspected and modified, and methods of objects to be executed.

Immediate Window

Visual Studio provides many tools that assist in debugging applications. The immediate window is one such tool. It allows you to interact with the executing program's state and execute instance and static methods when running in the debugger. This includes inspecting the values of variables, changing those values and performing calculations.

In this article we will demonstrate some of the features of the immediate window. To begin, create a new console application and add the following code to the Main method. Add a breakpoint on the second line of code and execute the program in Debug mode.

string msg = "Hello world";

Displaying the Immediate Window

The immediate window can be displayed in several ways. One is to open the "Debug" menu and the "Windows" submenu then select "Immediate". In some configurations of Visual Studio this menu option may not be present. In this case, you can press Ctrl-Alt-I, or Ctrl-D,I in Visual Studio 2010. Finally, if the shortcut key does not work, view the command window instead and enter the command "immed". The window should now be visible and active.

Visual Studio Immediate Window

Working With Variables

The most common use of the immediate window is to output the current values of variables and their properties. You should now be running the program in the debugger and the "msg" variable's value should have been set. To view the variable's value, simply type its name into the immediate window and press Enter. The value, "Hello world" will be displayed beneath the typed line, as in the image above.

"Hello World"

To access properties of a variable or value, use the member access operator (.) as you would within source code. You can also use Intellisense to help identify the property you wish to interrogate.


You can perform calculations by entering expressions. The following example doubles the length of the string and shows the result.

msg.Length * 2

In addition to viewing values you can modify variables using the assignment operator. The following changes the text in the msg variable. If you allow the Console.WriteLine command to execute you will see that the new message is displayed in the console window.

msg = "Good morning world"

You can also execute methods, both against objects and static versions. For example, to see the result of replacing the word "morning" with "evening" in our sample string, enter the following. Remember that if a method changes values elsewhere in your software that this may affect the continued execution of the program.

msg.Replace("morning", "evening")
"Good evening world"

Reusing Commands

If you are executing the same command, or similar commands, repeatedly in the immediate window you can reuse earlier entries. One way to do so is to click the command that you wish to reuse and press Enter. The line will be duplicated at the bottom of the immediate window. You can then edit the text and press Enter again to re-run the command.

If you prefer to use the keyboard you can press the up arrow key to retrieve the previously executed command. You may then cycle through the previous commands using the up and down arrow keys.

Clearing the Window

Sometimes you will want to clear the immediate window. To do so, right-click anywhere within the white area and choose "Clear All" from the menu that appears.

29 January 2010