Information Technology Reference
In-Depth Information
Table 2-1. The SimpleProgram Program, Line by Line
Line Number
Description
Tells the compiler that this program uses types from the System
namespace.
Line 1
Declares a new namespace, called Simple .
￿
Line 3
The new namespace starts at the open curly brace on line 4 and
extends through the matching curly brace on line 12.
￿
Any types declared within this section are members of the
namespace.
Line 5
Declares a new class type, called App .
￿
Any members declared between the matching curly braces on
lines 6 and 11 are members that make up this class.
Declares a method called Main as a member of class App .
￿In this program, Main is the only member of the App class.
￿ Main is a special function used by the compiler as the starting
point of the program.
Line 7
Line 9
Contains only a single, simple statement; this line constitutes the
body of Main .
￿ Simple statements are terminated by a semicolon.
￿ This statement uses a class called Console , in namespace
System , to print out the message to a window on the screen.
￿W thout the using statement in line 1, the compiler wouldn't
have known where to look for class Console .
More About SimpleProgram
A C# program consists of one or more type declarations. Much of this topic is spent explaining
the different types that you can create and use in your programs. The types in a program can
be declared in any order. In the SimpleProgram example, only the class type is declared.
A namespace is a set of type declarations associated with a name. SimpleProgram creates a
new namespace called Simple , and uses a predefined namespace called System .
To compile the program, you can use Visual Studio or the command-line compiler. To use
the command-line compiler, use the following command:
csc SimpleProgram.cs
In this command, csc is the name of the command-line compiler and SimpleProgram.cs is
the name of the source file.
Search WWH ::




Custom Search