Programming Help


A number of features in the IDE make it easier for programmers to write code. You should be familiar with Help in the IDE, so we won't talk too much about it. Help in Visual Studio is very simple—you just select what you don't understand and press F1. You almost always get what you're looking for. In this section, we'll go over some of the features of the IDE that you've probably used but that you might not be so familiar with.

IntelliSense

IntelliSense is one of those features that you start to rely on heavily as a programmer. It's a timesaving feature that can really help you do the right thing when you're typing code into the IDE. IntelliSense provides statement completion in the form of context-sensitive member lists that appear automatically as you type code into the Code Editor. These lists can save you a great deal of time when you're programming an unfamiliar API, and they can help you reduce errors that would normally be caught only at build time.

IntelliSense works by parsing the code you type into the Code Editor based on the project type context. This means that your source file needs to be part of a project or a solution before IntelliSense kicks in. IntelliSense is mostly automatic. It works on code that's part of the .NET Framework, and it works on external methods from references you've added to your project. It even works on XML Web services references that have been added to a project.

IntelliSense provides four major types of functionality when you're working with a supported language. Most programmers will use these four features—statement completion, parameter information, word completion, and code comments—in their automatic form; that is, they'll take the information as presented in the IDE without thinking too much about what's being shown. That's an absolutely valid way to use the technology. If this approach works for you and doesn't get in your way, IntelliSense is doing exactly what it's designed to do. You can also employ IntelliSense more deliberately by using the shortcuts associated with displaying IntelliSense information.

You might want to turn statement completion and parameter information off if you find them distracting, in which case you'll need to use the shortcuts, named commands, or toolbar buttons associated with the various IntelliSense features to display this information. To turn off statement completion in the Code Editor, go to the Text Editor folder in the Options dialog box. Select the language you want to apply your changes to, or select All Languages if you want to apply your changes universally. Open the General page, and, in the Statement Completion section, clear the Auto List Members check box. You can also toggle the Parameter Information setting from this page.

Note 

You can increase the number of options returned in a member list by clearing Hide Advanced Members. Hide Advanced Members is the default setting for Visual Basic, so you might be missing a number of possible completions if you leave that setting cleared.

With statement completion turned on, IntelliSense presents you with information as soon as you type an operator as part of a statement. If you have statement completion turned off or if you want to display this information immediately, press Ctrl+J. The result is shown in Figure 3-11.

image from book
Figure 3-11: Forcing statement completion by pressing Ctrl+J

To select an entry to complete a statement, use the up and down arrow keys to navigate to the desired completion and then press Tab.

To force parameter information like that shown in Figure 3-12, press Ctrl+Shift+Spacebar. This gives you a list of the parameter overloads you can choose from for a particular method. With the parameter information showing, use your up and down arrow keys to view the available parameters.

image from book
Figure 3-12: Viewing the parameter information for a method by pressing Ctrl+Shift+Spacebar

Use the parameter information provided by selecting the item that best suits your needs and then type the parameters into your method. You'll notice that after you type each parameter, the next parameter in the list appears in bold. Watching for this pattern helps ensure that every parameter in the list is entered correctly.

You might not be too familiar with the word completion feature if you're used to using IntelliSense automatically. Word completion lets you type in a few characters of a particular statement and get a list of possible completions for that statement. This functionality is a bit different from statement completion, which gives you a member list based on context. Word completion simply gives you a list of all the possible completions for the letters you've typed in. The shortcut for word completion is Alt+Right Arrow, but the statement completion shortcut (Ctrl+J) also works.

Finally, you might have noticed that when you hold your mouse pointer over an identifier in the Code Editor, ToolTip information appears. This ToolTip information is part of the Quick Info feature of IntelliSense, which contains the declaration for the identifier and any associated code comments. You can force this information by using Ctrl+K, Ctrl+I. You can add code comments to any method in Visual C# by typing /// (three forward slashes) on the line directly above the method definition. Even if you're not going to create documentation for your methods, IntelliSense makes code comments such as these helpful for letting another developer figure out how to use your code.

Brace Matching

Automatic brace matching is an IntelliSense feature that helps you determine whether braces in your code are matched properly. There are two types of brace matching in Visual Studio 2005. Rectangle brace matching happens when the cursor is next to the brace. Highlight brace matching works in Visual Basic, Visual C#, and Visual C++ and goes into effect when you type a closing brace into the Code Editor. The brace types affected include parentheses (), brackets [], and braces {}. In addition, the conditional macro expressions #if, #else, and #endif are matched as you type the closing expression, and quotation marks are matched when you type the closing set.




Working with Microsoft Visual Studio 2005
Working with Microsoft Visual Studio 2005
ISBN: 0735623155
EAN: 2147483647
Year: 2006
Pages: 100

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net