Appendix: Using Code Snippets

With code snippets, you have all the code you need at your fingertips. The lab document will tell you exactly when you can use them, as shown in the following figure.

Figure 5

Using Visual Studio code snippets to insert code into your project

To add a code snippet using the keyboard (C# only)

  1. Place the cursor where you would like to insert the code.
  2. Start typing the snippet name (without spaces or hyphens).
  3. Watch as IntelliSense displays matching snippets' names.
  4. Select the correct snippet (or keep typing until the entire snippet's name is selected).
  5. Press the Tab key twice to insert the snippet at the cursor location.

Figure 6

Start typing the snippet name

Figure 7

Press Tab to select the highlighted snippet

Figure 8

Press Tab again and the snippet will expand

To add a code snippet using the mouse (C#, Visual Basic and XML)

  1. Right-click where you want to insert the code snippet.
  2. Select Insert Snippet followed by My Code Snippets.
  3. Pick the relevant snippet from the list, by clicking on it.

Figure 9

Right-click where you want to insert the code snippet and select Insert Snippet

Figure 10

Pick the relevant snippet from the list, by clicking on it