Editing Code (Visual C#)
The Visual C# Code Editor is a word processor for writing source code. Just as Microsoft Word provides extensive support for sentences, paragraphs, and grammar, the C# Code Editor does the same for C# syntax and the .NET Framework. This support can be grouped into five main categories:
IntelliSense: Continually updated basic documentation on .NET Framework classes and methods as you type them in the editor, as well as automatic code generation.
Refactoring: Intelligent restructuring of your code base as it evolves over the course of a development project.
Code snippets: A library you can browse that contains frequently repeated code patterns.
Wavy underlines: Visual notifications of misspelled words, erroneous syntax, and warning situations as you type.
Readability aids: Outlining and colorization.
IntelliSense is the name of a set of related features that are designed to minimize the time you spend looking for help and to help you enter code more accurately and efficiently. These features all provide basic information about language keywords, .NET Framework types, and method signatures as you type them in the editor. The information is displayed in ToolTips, list boxes, and smart tags.
Many of the features in IntelliSense are shared with other Visual Studio languages and are documented with illustrations in thenode of the MSDN library. The following sections provide a brief overview of IntelliSense, with links to the more complete documentation.
As you enter source code in the editor, IntelliSense displays a list box that contains all the C# keywords and .NET Framework classes. If it finds a match in the list box for the name that you are typing, it selects the item. If the selected item is what you want, you can simply hit TAB and Intellisense will finish entering the name or keyword for you. For more information, see.
When you hover the cursor over a .NET Framework type, IntelliSense will display a Quick Info ToolTip that contains basic documentation about that type. For more information, see.
When you enter a .NET Framework type into the Code Editor, and then type the dot operator (.), IntelliSense displays a list box that contains the members of that type. When you make a selection and press TAB, IntelliSense enters the member name. For more information, see.
When you enter a method name in the Code Editor, and then type an opening parentheses, IntelliSense will display a Parameter Info ToolTip that shows the order and types of the method's parameters. If the method is overloaded, you can scroll down through all the overloaded signatures. For more information, see.
Sometimes you may attempt to create an instance of a .NET Framework class without a sufficiently qualified name. When this happens, IntelliSense displays a smart tag after the unresolved identifier. When you click the smart tag, IntelliSense displays a list of using directives that will enable the identifier to be resolved. When you select one from the list, IntelliSense adds the directive to the top of your source code file and you can continue coding at your current location. For more information, see.
As a code base grows and evolves over the course of a development project, it is sometimes desirable to make changes in order to make it more readable to humans, or more portable. For example, you may want to split some methods up into smaller methods, or change method parameters, or rename identifiers. The Refactoring feature, which is accessible by right-clicking in the Code Editor, does all this in a way that is much more convenient, intelligent, and thorough than traditional tools such as search and replace. For more information, see.
Code snippets are small units of commonly used C# source code that you can enter accurately and quickly with only a couple of keystrokes. The code snippet menu is accessed by right-clicking in the Code Editor. You can browse from among the many snippets provided with Visual C#, and you can also create your own. For more information, see.
Wavy underlines give you instant feedback on errors in your code as you type. A red wavy underline identifies a syntax error such as a missing semicolon or mismatched braces. A green wavy underline identifies a potential compiler warning, and blue identifies anissue. The following illustration shows a red wavy underline:
The Code Editor automatically treats namespaces, classes, and methods as regions that you can collapse in order to make other parts of the source code file easier to find and read. You can also create your own collapsible regions by surrounding code with the #region and #endregion directives.
The editor gives different colors to the various categories of identifiers in a C# source code file. For more information, see.