Code Editor

Developers can enter, delete, format, and edit code from the Code Editor window. The Code Editor includes features such as IntelliSense, code snippets, smart tags, and formatting options.

IntelliSense

IntelliSense suggests valid options for completing keystrokes for code snippets, types, members, and other information. It helps you enter information correctly and efficiently. It minimizes the keystrokes required to enter code while improving developer accuracy. IntelliSense is available in the Code Editor and other windows.

IntelliSense provides a dynamic drop-down list called the completion list. It appears as developers type new commands or identifiers. The completion list automatically appears when useful, such as after entering a dot (.) for a member. You also can prompt the completion list by pressing Ctrl+spacebar. The completion list might contain namespaces, types, type members, language keywords, and code snippets. The content depends on the context where the completion list is displayed. As text is entered, the nearest matching item in the list is selected. As more text is entered, the match is refined in the completion list. When the desired item is selected, press Tab to insert it. You also can select an item with the mouse. Assuming that the IntelliSense For Most Recently Used Members option is enabled, recently used items that match the input text are selected first. This option is set in the Options command on the Tool menu. It is enabled by default. Function overloads are not shown in the completion list. For example, there are several overloads of the Console.WriteLine method. However, WriteLine appears in the member list just once. The overload versions of a function, if any, are displayed by IntelliSense as you enter parameters.

IntelliSense displays the parameters of a function, including any overloaded versions, which have different signatures. Use the up and down arrows (shown in Figure 4-25) to cycle through the available overloads. Parameter information is presented after entering the open parentheses for a function. The Ctrl+Shift+spacebar combination of keystrokes displays parameter information on demand.

Parameter information for Console.WriteLine

Figure 4-25. Parameter information for Console.WriteLine

IntelliSense in Visual Studio 2008 automatically detects generics, types, and arguments. In the example shown in Figure 4-26, a generic dictionary is defined where entries have an integer key and a string value.

IntelliSense for a generic type

Figure 4-26. IntelliSense for a generic type

Have you ever attempted to use a type without the proper using statement? It requires stopping, researching the correct namespace, and then adding the using statement or explicitly specifying the namespace. The Add Using feature of IntelliSense automates this process—yet another way IntelliSense improves developer productivity.

When an unbound type is entered, a smart tag appears beneath the last character as a narrow red box. The smart tag is shown when the cursor is within the unbound text or immediately thereafter. From the Add Using smart tag menu (shown in Figure 4-27), you have two choices: Either insert the using statement or prefix the unbound type with the required namespace. Alternatively, right-click the unbound type, choose Resolve from the context menu, and then choose from the two submenu choices.

The Add Using smart tag menu

Figure 4-27. The Add Using smart tag menu

Surround With

You can surround code with an item from the completion list. For example, a block of statements can be surrounded with a for loop. The Surround With feature surrounds selected text with the selected item from the completion list. First select the text to be surrounded. Right-click the selected text and choose the Surround With command. The Surround With command displays the completion list. Select the item that should surround the text.

Font and Color Formatting

Visual Studio allows you to customize the font and color settings. Customize them in the Options dialog box, which is opened from the Tools menu. In the dialog box, expand the Environment node in the left-hand pane, and then select the Fonts And Colors node. Figure 4-28 shows the Fonts And Colors settings in the Options dialog box.

Fonts And Colors settings in the Options dialog box

Figure 4-28. Fonts And Colors settings in the Options dialog box

Source Code Formatting

Visual Studio 2008 provides excellent control of code formatting. You can control code indentation, line spacing, code spacing, and the wrapping of blocks. This is done in the Options dialog box on the Tools menu. Expand the Text Editor node in the left-hand pane, and then select the C# node. (See Figure 4-29.) The Tabs, Advanced, Formatting, and IntelliSense nodes provide additional options.

The General settings in the Text Editor, C# category of the Options window

Figure 4-29. The General settings in the Text Editor, C# category of the Options window

Change Tracking

Change tracking distinguishes saved from unsaved code. Visual Studio 2008 displays a colored bar on the left of the Code Editor window to indicate the code status. Saved code has a green bar, while unsaved code has a yellow bar. Original code, which is code that is unchanged since the source file was opened, has no colored bar at all.

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

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