C# Program to Demonstrate the Use of GetCommandLineArgs() Method of Environment Class
Environment Class provides information about the current platform and manipulates, the current platform. It is useful for getting and setting various operating system-related information. We can use it in such a way that retrieves command-line arguments information, exit codes information, environment variable settings information, contents of the call stack information, and time since last system boot in milliseconds information. In this article, we will demonstrate the use of the GetCommandLineArgs() Method of the Environment Class. This method is used to get command-line arguments for the current process and returns an array of strings that contains arguments passed on the command line. The command-line arguments are generally delimited by spaces and we can use double quotation marks (“) to include spaces within an argument. Whereas the single quotation mark (‘), does not give the same functionality. When a double quotation mark follows an even number of backslashes, then the starting pair of backslashes were replaced with the one backslash, and the double quotation marks are also removed. For example: input: MyData \\\\”app1 \\\\”app2, output: MyData \\\app1, \\app2. And when a double quotation mark follows an odd number of backslashes, then the starting pair of backslashes were replaced with the one backslash and the remaining backslashes were removed. In this situation, double quotation marks will not remove. For example: input: MyData \\\\\”app1 \”app2, output: MyData \\”app1, “app2
public static string GetCommandLineArgs ()
Return: It returns an array of strings that holds the command-line arguments for the currently running process. In this array, the first item is the executable file name and the remaining items are the command line arguments.
NotSupportedException: This exception is thrown when an invoked method is not supported, or when there is an attempt to read, seek, or write to a stream that does not support the invoked functionality.
Input : c/cpp java python Output : c/cpp java python Input : 11 java python Output : 11 java python
Command Line Arguments are: /Users/Projects/newprogram/newprogram/bin/Debug/netcoreapp3.0/newprogram.dll