Microsoft visual studio – Immediate Window – Simple and Troubleshooting Tips.

Dear all,

This is my second blog. today i have try to explorer one of the most useful window provided in Microsoft visual studio i.e. Immediate Window.this window allows you to evaluate variable,expressions at debug mode.

this is very useful window and can save your couple of minutes or even hours so you can leave for home early:).

How to open Immediate Window

The immediate window can be displayed in several ways.

1.One is to open the “Debug” menu and the “Windows” submenu then select “Immediate”.

2.In some configurations of Visual Studio this menu option may not be present.

a)In this case, you can press Ctrl-Alt-I, or Ctrl-D,I in Visual Studio 2010.

b)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.

Lets begin with example

Screenshot

Scenario 1.

In above example we create List named “lst” and Add two item “a” and “b” and then debugger hit at specified breakpoint.

suddenly we realized that we forgot to add item suppose “c”.OK, here immediate window coming to the rescue.Just run following command in immediate window

lst.Add(“c”);

then check item count of variable lst in visual studio, it will 3.

you can realized that new item “c” added in List.

Scenario 2

suppose  we need to check element at position 0 at List lst then run following command in immediate.

?lst[0]

Output will be “a”

Scenario 3.

Suppose I want to check function output at design time i.e. without debugging , in that case Immediate Window can solve your problem.

Lets consider following very simple function

public static int Add(int a, int b)
        {
            return a + b;
        }

Run following command in Immediate Window
?Add(1,2)
Output will be 3

Scenario 4.

you can also compare value of any variable at run time by using == operator.

Run following command in Immediate Window

?lst[0]==”c”

output will be True or False based of value of lst[0].

Thanks,

comments and reply are truly appreciated.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s