System.Environment.GetCommandLineArgs Method

Returns a string array containing the command-line arguments for the current process.

Syntax

public static string[] GetCommandLineArgs ()

Returns

An array of string where each element contains a command-line argument. The first element is the executable file name, and the following zero or more elements contain the remaining command-line arguments.

Remarks

The first element in the array contains the file name of the executing program. If the file name is not available, the first element is equal to string.Empty. The remaining elements contain any additional tokens entered on the command line.

The program file name can, but is not required to, include path information.

Command line arguments are delimited by spaces. You can use double quotation marks (") to include spaces within an argument. The single quotation mark ('), however, does not provide this functionality.

If a double quotation mark follows two or an even number of backslashes, each proceeding backslash pair is replaced with one backslash and the double quotation mark is removed. If a double quotation mark follows an odd number of backslashes, including just one, each preceding pair is replaced with one backslash and the remaining backslash is removed; however, in this case the double quotation mark is not removed.

The following table shows how command line arguments can be delimited, and assumes MyApp as the current executing application.

MyApp alpha beta

MyApp, alpha, beta

MyApp "alpha with spaces" "beta with spaces"

MyApp, alpha with spaces, beta with spaces

MyApp 'alpha with spaces' beta

MyApp, 'alpha, with, spaces', beta

MyApp \\\alpha \\\\"beta

MyApp, \\\alpha, \\beta

MyApp \\\\\"alpha \"beta

MyApp, \\"alpha, "beta

To obtain the command line as a single string, use the Environment.CommandLine property.

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0