The code editor displays different types of code items in different colors (although they all appear black or gray in this book). You can change the colors used for different items by selecting the Tools menu’s Options command and opening the Environment ⇒ Fonts and Colors option page.
The following table describes some of the default colors that the code editor uses to highlight different code elements.
ITEM | HIGHLIGHTING |
Comment | Green text |
Compiler error | Underlined with a wavy blue underline |
Keyword | Blue text |
Other error | Underlined with a wavy purple underline |
Preprocessor keyword | Blue text |
Read-only region | Light gray background |
User-defined types | Navy text |
Warning | Underlined with a wavy green underline |
A few other items that may sometimes be worth changing have white backgrounds and black text by default. These include identifiers (variable names, types, object properties and methods, namespace names, and so forth), and numbers.
When the code editor finds an error in your code, it highlights the error with a wavy underline. If you hover over the underline, the editor displays a tooltip describing the error. If Visual Studio can guess what you are trying to do, it adds a small flat rectangle to the end of the wavy error line to indicate that it may have useful suggestions.
The assignment statement i = "12" shown in Figure 5-6 has an error because it tried to assign a string value to an integer variable and that violates the Option Strict On setting. The editor displays the wavy error underline and a suggestion indicator because it thinks it knows a way to fix this error. The Error List window at the bottom also shows a description of the error.
If you hover over the suggestion indicator, the editor displays an error correction icon. If you click the icon, Visual Studio displays a dialog box describing the error and listing some actions that you may want to take. Figure 5-7 shows the suggestion dialog box for the error in Figure 5-6. If you click the text over the revised sample code, or if you double-click the sample code, the editor makes the change.