Programming languages make use of parentheses, braces, brackets, and other delimiters to delimit function arguments, mathematical functions/order of operation, and bodies of code. It can be difficult to visually determine whether you have missed a matching delimiter—that is, if you have more opening delimiters than you have closing delimiters—especially with highly nested lines of code.
Brace matching refers to visual cues that the code editor uses to make you aware of your matching delimiters. As you type code into the editor, any time you enter a closing delimiter, the matching opening delimiter and the closing delimiter are briefly highlighted. In Figure 7.25, brace matching helps to indicate the matching delimiters for the interior for
loop.
Tip
You also can trigger brace matching simply by placing the cursor directly to the left of an opening delimiter or the right of a closing delimiter. If you are browsing through a routine congested with parentheses and braces, you can quickly sort out the matching pairs by moving your cursor around to the various delimiters. If you want to move to the second member of a pair, you can press Ctrl+^.
Although this feature is referred to as brace matching, it actually functions with the following delimiters:
Parentheses: ()
Brackets: []
, <>
Quotation marks: ""
Braces: {}
In the case of C#, brace matching also works with the following keyword pairs (which essentially function as delimiters using keywords):
#region
, #endregion
#if
, #else
, #endif
case
, break
default
, break
for
, break
, continue
if
, else
while
, break
, continue