Datasheet
36
❘
CHAPTER 1 VISUAL STUDIO 2010
static VariableName string, which is acting as a placeholder. Once you have entered the variable name you want,
you can just press Tab. At that point the editor automatically jumps to the next highlighted item. This capability
to insert a block of boilerplate code and have it automatically respond to your customization is extremely useful.
Code expansion enables you to quickly shift between the values that need to be customized, but these values
are also linked where appropriate, as in the next example. Another code expansion shortcut creates a new
property in a class. If at the class level you type the letters “ prop ” and then press the Tab key twice, after the
fi rst tab you ’ ll fi nd that your letters become the word “ Property ” ; and after the second tab the code shown in
Figure 1 - 19 will be added to your existing code. On the surface this code is similar to what you see when you
expand the
Select statement. Note that although you type prop , even the internal value is part of this code
expansion. Furthermore, although Visual Basic implemented a property syntax that is no longer dependent on
an explicit backing fi eld, this expansion provides the more robust syntax that uses an explicit backing fi eld.
FIGURE 1 - 19
The difference, however, is that the same value String in Figure 1 - 19 is repeated for the property. The value
you see is the default. However, when you change the fi rst such entry from String to Integer , Visual Studio
automatically updates all three locations because it knows they are linked. Using the code shown in Figure 1 - 19,
update the property value to be
m_Count . Press Tab and change the type to Integer ; press Tab again and label
the new property
Count . This gives you a simple property on this form for use later when debugging.
The completed code should look like the following block:
Private m_Count As Integer
Public Property Count() As Integer
Get
Return m_Count
End Get
Set(ByVal value As Integer)
m_Count = value
End Set
End Property
Code snippet from Form1
CH001.indd 36CH001.indd 36 4/5/10 11:56:51 AM4/5/10 11:56:51 AM