Microsoft 9GD00001 Computer Accessories User Manual


 
Chapter 2: Learning Just Enough C# or VB.NET: Basic Syntax 49
Coding Expressions and Statements
There are various types of statements you can write with both C# and VB, including
assignment, method invocations, branching, and loops. We’ll start off by looking at
primitive types, such as integers and strings, and then I’ll show how to build expressions
and set values by performing assignments. Then you’ll learn about branching statements,
such as if and switch in C# or the case statement in VB. Finally, you’ll learn about various
loops, such as for and while. I describe these language features in general terms because
they differ between C# and VB, but you’ll learn that the concepts are essentially the same.
Before writing any code, you should know how Intellisense works; it is an important
productivity tool that reduces keystrokes for common coding scenarios.
Making Intellisense Work for You
Previously, you saw how snippets work. Snippets use Intellisense to show a completion
list. Intellisense is integrated into the VS editor, allowing you to complete statements with
a minimum number of keystrokes. The following walkthrough shows you how to use
Intellisense, as we add the following line to the Main method. Don’t type anything yet;
just follow along to see how Intellisense works:
C#:
Console.WriteLine("Hello from Visual Studio 2010!");
VB:
Console.WriteLine("Hello from Visual Studio 2010!")
The following steps show you how VS helps you save keystrokes:
1. Inside the braces of the Main method, type c and notice how the Intellisense window
appears, with a list of all available identifiers that start with c. This list is called a
completion list.
2. Type o and notice that the completion list filters all but those identifiers that begin
with co.
3. Type n and you’ll see that the only identifier available is Console. This is what we
want, and you only needed to type three characters to get there.
4. At this point most people press the ENTER or TAB key to let VS finish typing Console,
but that is effectively a waste of a keystroke.