52Microsoft Visual Studio 2010: A Beginner’s Guide
To run with debugging, either select Debug Start Debugging or press F5. Because of the way the application is coded so far, the Command Prompt window will quickly run and close; you might miss it if you blink your eyes. To prevent this, you can add a Console.ReadKey statement below Console.WriteLine, which will keep the window open until you press any key. Here’s the updated Main method:
C#:
static void Main(string[] args)
{
Console.WriteLine("Hello from Visual Studio 2010!"); Console.ReadKey();
}
VB:
Sub Main()
Console.WriteLine("Hello from Visual Studio 2010!")
Console.ReadKey()
End Sub
Pressing F5 will show “Hello from Visual Studio 2010!” on the Command Prompt window, just as when running without debugging.
To understand why there are two options, think about the difference between just running a program and debugging. If you run a program, you want it to stay open until you close it. However, if you are debugging a program, you have most likely set a breakpoint and will step through the code as you debug. When your debugging session is over, you want the program to close so that you can start coding again right away.
Now that you know how to add code to the Main method and run it, you can begin looking at the building blocks of algorithms, starting in the next section.
Primitive Types and Expressions
The basic elements of any code you write will include primitive types and expressions, as explained in the following sections.
Primitive Types
You can define variables in your programs whose type is one of the primitive types. Variables can hold values that you can read, manipulate, and write. There are different types of variables, and the type specifies what kind of data the variable can have. In .NET there are primitive types (aka