Hack 8. Master IntelliSense![]() have Visual Studio's IntelliSense feature do lots of the typing for you. Even if you have used Visual Studio only a couple times, I am sure you have noticed one of its trademark features: IntelliSense. The most popular form of IntelliSense assists you as you code by providing a list of the members for each class immediately after you finish typing the class name (and the following period). This is not the only form of IntelliSense though; this feature finds its way into a multitude of different areas of Visual Studio. 2.4.1. Complete WordThe first, and most useful, IntelliSense feature is actually just a shortcut: Ctrl-Space (Edit.CompleteWord). By using the Ctrl-Space shortcut, you can summon IntelliSense at any point during your coding session, not just when you finish typing a class name. This is one of the few shortcuts that can really change the way that you write code.If you have already starting typing when you press Ctrl-Space, Visual Studio will take one of two actions. If there is only one object that matches what you have typed in so far, it will automatically complete the object name; for instance, if you typed in HttpR, it would automatically complete the rest of the object name (HttpRequest). If there are a number of objects that match what you have typed in, it will display the full list of members with the first match highlighted. Figure 2-7 shows what the listbox would look like if you only typed in the letter P. Figure 2-7. IntelliSense listbox, brought to you by the letter P![]() list of members in the current context. This is a great way to find a variable name that has slipped your mind. Figure 2-8 shows an example of this. Figure 2-8. IntelliSense listbox showing all members![]() member variables with a common prefix; for instance, if all of your variables are prefixed with "_", by typing _ and then pressing Ctrl-Space, you would display a list of all of your variables to choose from. 2.4.2. Parameter InfoAnother useful form of IntelliSense is the parameter information that is shown after you type the opening parenthesis of a method (it goes away when the parentheses are closed). When editing an already existing method, it would be nice to have this information again without having to delete and then reenter the opening parenthesis, wouldn't it? As long as the cursor is located inside of the method parameters parenthesis, pressing Ctrl-Shift-Space (Edit.ParameterInfo) will display the parameter information pop up. Figure 2-9 shows this pop up. Figure 2-9. Parameter info IntelliSense pop up![]() 2.4.3. Quick InfoWhen you move your mouse over a method or variable, you will see a small tool tip pop up that contains information about that method or variable. This is commonly called Quick Info. If you are navigating by keyboard, you can also get this small pop up by pressing Ctrl-K and then Ctrl-I (Edit.QuickInfo). Using this shortcut is also the only way to bring up this informational pop up during debug, since the default behavior is to show the value of the object you are hovering over when using the mouse. 2.4.4. Stub CompletionAnother form of autocompletion called stub completion can be very useful when working with interfaces or event handlers or when overriding a method. This feature can be used to automatically stub out the methods required by the interface or the default code for an overridden method or event handler. This is a feature that was added to Visual Studio .NET 2003, but its presence is not always obvious when you are coding quickly. 2.4.4.1 InterfaceWhen you first create a class and add the interface name after the colon (or the Implements in Visual Basic), a small yellow window will pop up for just a few seconds, offering you the ability to press the Tab key, as shown in Figure 2-10. Figure 2-10. Interface IntelliSense prompt![]() methods required by the interface will be automatically added to your class, including TODO comments to remind you to complete the methods: public class CarCollection : IEnumerable 2.4.4.2 Overriding methodsWhen you type override into the document window, you will see a list of methods you can override in the base class. This can be seen in Figure 2-11. Figure 2-11. Override IntelliSense![]() create the method and automatically add a call to the method you are overriding on your base class like this: public override void Start( ) 2.4.4.3 Event handlersWhen adding a new event handler to your class, Visual Studio will automatically create the stub of this event handler, much as when working with an interface. When you type the code to add an event handler to an event, you will see a prompt inviting you to press the Tab key, as shown in Figure 2-12. Figure 2-12. EventHandler IntelliSense before pressing the Tab key![]() Figure 2-13. Figure 2-13. EventHandler IntelliSense after pressing the Tab key![]() into your document: private void Car_OnStart(object sender, EventArgs e) 2.4.5. IntelliSense CommentsWhen comments exist for a method or class, they are displayed in the IntelliSense pop up shown in Figure 2-14. Figure 2-14. IntelliSense comments![]() using C#, then these comments are pulled from the XML-based comments in your code, like the following example: /// <summary>If you are using C++, these comments are generated based on any comments at the end of the line for the member; if no comments exist at the end of the line, then any comments on the line directly above the member are used. Any comments on the declaration are used first; if there are no comments on the declaration, any comments on the definition are used. To get this same functionality with VB.NET, you will need to install the VBCommenter power toy [Hack #70] .IntelliSense is one of the best features of Visual Studio, and using the shortcut keys summarized in Table 2-1 will allow you to get the most out of this great feature. 2.4.6. See Also[Hack #32] |