Providing Entry and Exit Points

Providing Entry and Exit Points

In order for the runtime environment to load and start a class, it needs to know where to begin. The Java language has the programmer define a public static void main( String[] args ) method so that the JVM may be able to pass the command line arguments into that method and start the program. In order to be more flexible (and more C-like), C# allows the programmer three different method signatures for the entry point. The simplest one is the public static void Main() method, followed by the public static void Main( string[] args ) and the public static int Main( string[] args )" methods. The last two signatures have the ability to take in the command line parameters passed into the program, and the third has the ability of returning an exit code.

But just like Java, having an entry point that does not have a return value does not mean that the exit code of the program cannot be set. In Java, the programmer can call System.exit( int code ) with the value to exit with. A C# programmer can set the ExitCode property in the System.Environment class and when System.WinForms.Application.Exit() is called, the value of ExitCode is returned to the run time environment.

posted on 2005-05-10 15:24  我在等待  阅读(477)  评论(0)    收藏  举报