13.07.2015 Views

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 10 Basic concepts10. Basic concepts10.1 Application startupApplication startup occurs when the execution environment calls a designated method, which is referred toas the application's entry point. This entry point method is always named Main, and shall have one of thefollowing signatures:static void Main() {…}static void Main(string[] args) {…}static int Main() {…}static int Main(string[] args) {…}As shown, the entry point may optionally return an int value. This return value is used in applicationtermination (§10.2).The entry point may optionally have one formal parameter, and this formal parameter may have any name. Ifsuch a parameter is declared, it must obey the following constraints:• The implementation shall ensure that the value of this parameter is not null.• Let args be the name of the parameter. If the length of the array designated by args is greater thanzero, the array members args[0] through args[args.Length-1], inclusive, must refer to strings,called application parameters, which are given implementation-defined values by the host environmentprior to application startup. The intent is to supply to the application information determined prior toapplication startup from elsewhere in the hosted environment. If the host environment is not capable ofsupplying strings with letters in both uppercase and lowercase, the implementation shall ensure that thestrings are received in lowercase. [Note: On systems supporting a command line, application parameterscorrespond to what are generally known as command-line arguments. end note]Since <strong>C#</strong> supports method overloading, a class or struct may contain multiple definitions of some method,provided each has a different signature. However, within a single program, no class or struct shall containmore than one method called Main whose definition qualifies it to be used as an application entry point.Other overloaded versions of Main are permitted, however, provided they have more than one parameter, ortheir only parameter is other than type string[].An application can be made up of multiple classes or structs. It is possible for more than one of these classesor structs to contain a method called Main whose definition qualifies it to be used as an application entrypoint. In such cases, one of these Main methods must be chosen as the entry point so that application startupcan occur. This choice of an entry point is beyond the scope of this specification—no mechanism forspecifying or determining an entry point is provided.In <strong>C#</strong>, every method must be defined as a member of a class or struct. Ordinarily, the declared accessibility(§10.5.1) of a method is determined by the access modifiers (§17.2.3) specified in its declaration, andsimilarly the declared accessibility of a type is determined by the access modifiers specified in itsdeclaration. In order for a given method of a given type to be callable, both the type and the member must beaccessible. However, the application entry point is a special case. Specifically, the execution environmentcan access the application's entry point regardless of its declared accessibility and regardless of the declaredaccessibility of its enclosing type declarations.In all other respects, entry point methods behave like those that are not entry points.10.2 Application terminationApplication termination returns control to the execution environment.69

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!