Udostępnij za pośrednictwem


Code Colorization

The code editor parses tokens and code constructs so they are easily recognizable and distinguishable from other code content in the code editor. After the code editor parses your code, it colorizes code constructs appropriately.

Tokens

The code editor colorizes the following token types.

  • Comment

  • Excluded Code

  • Identifier

  • Keyword

  • Number

  • Operator

  • Preprocessor Keyword

  • String

  • String (C# @ Verbatim)

  • User Types

  • User Types (Value Types)

  • User Types (Enums)

  • User Types (Delegates)

  • XML CData Section

  • XML Doc Attribute

  • XML Doc Comment

  • XML Doc Tag

You can modify the default colorization setting by using the Fonts and Colors, Environment, Options Dialog Box.

Contextual Keywords

The code editor colorizes contextual keywords appropriately. In the following example, the type yield is colorized teal, and the keyword yield is colorized blue.

Code Colorization image

For a complete list of contextual keywords, see C# Keywords.

Brace Matching Colorization

The code editor facilitates bold colorization or highlight colorization for brace matching.

Bold Colorization

When you change any part of the following code construct pairs, the string or code construct pairs are briefly displayed in bold to indicate an association between them:

" "

A string

@" "

A verbatim string

#if, #endif

Preprocessor directives for conditional sections

#region, #endregion

Preprocessor directives for conditional sections

case, break

Control statement keywords

default, break

Control statement keywords

for, break

Evaluation expression keywords

for, continue

Evaluation expression keywords

foreach, break

Evaluation expression keywords

foreach, continue

Evaluation expression keywords

while, break

Evaluation expression keywords

while, continue

Evaluation expression keywords

You can disable this feature by clearing the Automatic delimiter highlighting property in the General, Text Editor, Options Dialog Box.

Highlight Colorization

When the pointer is positioned immediately before a starting delimiter, or immediately after an ending delimiter, gray rectangles appear to highlight both starting and ending delimiters to indicate an association between them. This feature is available for the following matching pairs:

{ }

braces

[ ]

brackets

( )

parenthesis

Example

To illustrate brace matching colorization, type (do not copy and paste) the following code in the code editor.

class A
{
     public A()
     {
          if(true)
               int x =0;
          else
               int x =1;
     }
}

Colorization Settings

Colorization settings are persisted through Visual Studio Settings.

See Also

Reference

Automatic Brace Matching