Monday, May 21, 2007

The Main() Function

The Main() is the entry point for a C# application. When the execution is initiated, the Main() function executes and when the Main() function finishes the execution ends. There are four possible signatures you can use for the Main() function:
· Static void Main ()
· Static void Main (string[] args)
· Static int Main ()
· Static int Main (string[] args)
The args parameter of Main() is a method for accepting information from outside the application, specified at runtime. This information takes the form of command-line parameters. i.e. any command-line parameters that are specified are placed in this args array.

How do you add the command-line arguments?
The below method is the easiest way to add the arguments, rather than typing them at a command-line prompt every time.
· Right-click the project name in the Solution Explorer window and select Properties.
· Select the Debug page and add whatever command-line arguments you want to the Command Line Arguments setting
· Run the Application

No comments: