Information Technology Reference
In-Depth Information
This code produces the following output:
Jon
Peter
Beth
Julia
Tammi
Other important things to know about
Main
are the following:
Main
must always be declared
static
.
Main
can be declared in either a class or a struct.
A program can contain only one declaration of the four acceptable entry point forms of
Main
. You can, however, legally declare other methods named
Main
, as long as they don't have
any of the four forms listed previously—but doing this is inviting confusion.
Accessibility of Main
Main
can be declared
public
or
private
:
f
Main
is declared
private
, other assemblies cannot access it, and only the execution
environment can start the program.
f
Main
is declared
public
, other assemblies can call it and thereby start the program.
The execution environment, however,
always
has access to
Main
, regardless of its declared
access level, or the declared access level of the class or struct in which it is declared.
By default, when Visual Studio creates a project, it creates a program outline where
Main
is
implicitly
private
. You can always add the
public
modifier if you need to.