60Microsoft Visual Studio 2010: A Beginner’s Guide

Figure 2-13 A switch snippet template

is required. When the program executes a break statement, it stops executing the switch statement and begins executing the next statement after the last curly brace of the switch statement.

For the VB example, the Select Case statement uses name as the condition and executes code based on which case matches name. The Case Else code block will run if no other cases match.

Switch Statement Snippets

There are two scenarios for switch statement snippets: a minimal switch statement and an expanded switch with enum cases. First, try the minimal switch statement by typing sw and pressing TAB, TAB, resulting in the switch statement in Figure 2-13.

You would replace the switch_on in Figure 2-13 with a value you want to use in the switch statement. After pressing ENTER, you’ll see the snippet expand to a switch statement with a default case, as follows:

switch (name)

{

default:

break;

}

VB Select statements work similar to the C# switch; type Se and press TAB, TAB; you’ll see the VB template shown in Figure 2-14.

Figure 2-14 The Select Case snippet template

Page 83
Image 83
Microsoft 9GD00001 manual Switch Statement Snippets, a switch snippet template