The arguments which are passed by the user or programmer to the Main() method is termed as Command-Line Arguments. Main() method is the entry point of execution of a program. Main() method accepts array of strings. But it never accepts parameters from any other method in the program. In C# the command line arguments are passed to the Main() methods by stating as follows:
static void Main(string args) or static int Main(string args)
Note : To enable command-line arguments in the Main method in a Windows Forms Application, one must manually modify the signature of Main in program.cs. Windows Forms designer generates code and creates Main without an input parameter. One can also use Environment.CommandLine or Environment.GetCommandLineArgs to access the command-line arguments from any point in a console or Windows application.
To Compile and execute the above program follow below commands :
Compile: csc Geeks.cs Execute: Geeks.exe Welcome To GeeksforGeeks!
Arguments Passed by the Programmer: Welcome To GeeksforGeeks!
In above program Length is used to find the number of command line arguments and command line arguments will store in args array. With the help of Convert class and parse methods, one can also convert string argument to numeric types. For examples:
long num = Int64.Parse(args); or long num = long.Parse(args);
This will changes the string to a long type by using the Parse method. It is also possible to use the C# type long, which aliases Int64. Similarly one can parse using predefined parsing methods in C#.