Microsoft 9GD00001 Computer Accessories User Manual


 
Chapter 2: Learning Just Enough C# or VB.NET: Basic Syntax 47
The Options window in Figure 2-6 is opened to Text Editor, C#, Formatting New
Lines. As you can see, there are very detailed settings for even how the editor automatically
formats new lines and where braces appear. If the code doesn’t format the way you want it
to, visit this page to set the options to what you please.
Saving Time with Snippets
Snippets are important to learn because they will save you time. A snippet is a set of
keystrokes that form a template for a piece of code. The code for a snippet is typically
something that is common in normal programming. You’ll see many common statements
and blocks of code in this chapter, many of which have associated snippets. This section
shows you the mechanics of using snippets, and you’ll see more examples throughout the
rest of this chapter.
To use a snippet, begin typing the snippet prefix until the snippet acronym appears in
the Intellisense completion list, press the
TAB key twice, and fill in the snippet form while
tabbing through each field. Press
ENTER when you’re done.
Since you’ve already learned about namespaces, I’ll show you the namespace snippet.
To start, open any code file and click to start typing in a part of the file outside of all code
blocks, such as directly below any using statements but above any existing namespace
statements. Type the letter n and watch the completion list go straight to the namespace
element. Type an a and you’ll see the namespace alone in the completion list, as shown
in Figure 2-7.
NOTE
The CTRL-ALT-SPACE keystroke in Figure 2-7 switches between the Intellisense modes
Consume First and Standard mode. In Standard mode, which shows CTRL-ALT-SPACE,
typing characters automatically selects keywords. However, there are situations where
you are trying to type a word that doesn’t exist yet and Intellisense is too aggressive by
adding the selected completion list item, instead of what you typed. In those cases, you
can press the
CTRL-ALT-SPACE keys to go to Consume First mode and what you’ve typed will
be selected. You can still use the DOWN ARROW key on your keyboard in Consume First
mode to select the highlighted term in the completion list.
Figure 2-7 Using snippets