Search

Using Immediate Window to Work with Values

3 min read
2 views

This article is an excerpt from the book: Murach's ASP.NET 2.0 Web Programming with C# 2005. The Immediate window, shown in figure 4-14, is useful for displaying the values of variables or properties that don't appear in the Code Editor window. To display a value, you simply type a question mark followed by the name of the variable or property. The first line of code in this figure, for example, displays the Text property of the item selected from the Products drop-down list. You can see the result in the second line of this window. The Immediate window is also useful for executing C# statements. For example, you can execute an assignment statement to change the value of a variable or property. After I displayed the Text property of the Quantity text box, for example, I assigned a value of 1 to this property. Similarly, you can execute a user-defined method. This can be useful for testing the result of a method with different arguments. If you execute a method that returns a value, you can also preface the method name with a question mark to display the value it returns. When you enter commands in the Immediate window, they're executed in the same context (or scope) as the application that's running. That means that you can't display the value of a variable that's out of scope. If you try to do that, the debugger displays an error message. The commands that you enter into the Immediate window remain there until you exit from Visual Studio or explicitly delete them using the Clear All command in the shortcut menu for the window. That way, you can use standard Windows techniques to edit and reuse the same commands from one execution of an application to another without having to reenter them. To execute a command that you've already entered in the Immediate window, just use the Up and Down arrow keys to scroll through the commands. As you scroll, the commands are displayed at the bottom of the window. Then, you can change a command if necessary and press Enter to execute it. The Immediate window

Suggest a Correction

Found an error or have a suggestion? Let us know and we'll review it.

Share this article

Comments (0)

Please sign in to leave a comment.

No comments yet. Be the first to comment!