41.4. Immediate Window

Quite often when you are writing code or debugging your application, you will want to evaluate a simple expression either to test a bit of functionality or to remind yourself of how something works. This is where the Immediate window comes in handy. This window enables you to run expressions as you type them. Figure 41-4 shows a number of statements — from basic assignment and print operations through to more advanced object creation and manipulation.

Figure 41.4. Figure 41-4

Figure 41-4 shows a new Customer object being created in a C# project within the Immediate window. Within a Visual Basic project you can't do explicit variable declaration (for example, Dim x as Integer). Instead it is done implicitly using the assignment operator.

One of the more useful features of the Immediate window is that it can be used while you are writing code. When you create new objects in the Immediate window at design time, it will create an instance of that object using the Object Test Bench. If you invoke a method or property that contains an active breakpoint, Visual Studio will change to debug mode and break at the breakpoint. This is particularly useful if you are working on a particular method that you want to test without running the entire application.

The Immediate window supports a limited form of IntelliSense, and you can use the arrow keys to track back through the history of previous commands executed.

IntelliSense is only supported in the Immediate window when running in debug mode, not during design-time debugging.

The Immediate window also allows you to execute Visual Studio commands. To submit a command you must enter a greater than symbol (>) at the start of the line. There is an extremely large set of commands available; in fact almost any action that can be performed within Visual Studio is accessible as a command. Fortunately, IntelliSense makes navigating this list of available commands a little more manageable.

There is also a set of almost 100 predefined aliases for commands. One of the more well-known aliases is "?", which is a shortcut for the Debug.Print command that prints out the value of a variable. You can see the full list of predefined aliases by entering >alias, as shown in Figure 41-5.

Figure 41.5. Figure 41-5

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.70.185