C#: Variations on the Main() method, System.Environment.GetCommandLineArgs()

Below are a few different variations that can be done on the Main method.

Return type is void, string array as argument:

Return type is void, no arguments:

Return type is int, no arguments:

Return type is int, string array as argument:

Besides accessing them via the ‘string[] args’ parameter, you can access command-line arguments using

When you do this, you are not required to define the Main() method as taking a string array.

Leave a Reply

Your email address will not be published. Required fields are marked *