Main, args.` Every program has a Main entry point. In Main, we access a string array called args. This array is populated with command-line arguments from the operating system. This makes it possible to configure programs with minimal complexity. `String Array `array`Example.` When you create a new console application in the C# language using Visual Studio, you will get a Main method with a signature similar to the one shown here. It will have a string[] args parameter and void return type. `Args `args`Void `void`You can use a Main method that returns an int or that receives no parameters if you want to.`Return `return`Int `int`Next: `This program shows how the command-line parameters are received from a Windows command line.`Main can be defined` in any valid class name. Note that you must have a class enclosing all methods in your C# program. Upon startup the Main method is executed. It then tests for a null array argument—this is never reached. `Class `class`Then: `It prints the array length and then writes the arguments as strings with Console.WriteLine.`Console.WriteLine `console`The "Output" section of the example shows possible command lines and the program's actual output.`Whitespace.` More than one whitespace is discarded when separating the arguments. So if you separate parameters by two spaces, there is no difference from separating with one space. But with the string literal syntax, enclosed whitespace is retained. `If you want to preserve whitespace on the command line, use the quotation marks around your parameter.`Null.` In my testing, you will not encounter a null parameter array in the Main entry point. So if you execute a program with no command-line parameters, you will not receive a null string array reference in the Main method. `Null `null`However,` if incorrect parameters are likely, it is best to wrap the Main entry point with try, catch and finally blocks. This ensures the best possible execution paths are taken. If a step is critical, put it in a finally block. `Try `try`Catch `catch`Finally `finally`Signature.` You can change the signature of the Main method in your program and the program will still compile and execute correctly. You can demand that the Main method return an int. This tells the operating system the program's result. `It is also useful to omit the string[] args parameter array entirely when not needed.`This site almost always omits the parameter array to shorten the example programs and improve clarity.`Shortcut.` In Windows, you can open your program's Release or Debug directory and create a shortcut to your application and specify command-line parameters in that shortcut. Right-click on the EXE file and select Create Shortcut.`Then,` in the "Target" text box in the Shortcut Properties window, append the command-line arguments after the file name. When you click on the shortcut, these strings will be put into the string[] args array at runtime in the Main method.`Summary.` We saw the exact behavior of the Main entry point when used with an args string array. We saw examples of calling the Main method from the Windows operating system with shortcuts. We noted how whitespace in the command-line is handled.

ETOINOOTDTQTbTJTAO{OET?TcNTrN(TP[] args)OE{OEETmargsTxnull)OEE{OEEET'NIargs is nullIN);OEE}OEEelseOEE{OEEET5.Ta(NIargs lT^ is IN);OEEET'args.LT^);OEEETw(TiiTy0; i < args.LT^; i++)OEEE{OEEEETP argumentTyargs[i];OEEEET5.Ta(NIargs index IN);OEEEET5.Ta(i);N T{Ta indexOEEEENT5.Ta(NI is [IN);OEEEET5.Ta(argument);N T{Ta TPOEEEENT'NI]IN);OEEE}OEE}OEET5.TuLine();OE}O}OONOONIC:\T5Application1.exeI a b cNOargs lT^ is 3Oargs index 0 is [a]Oargs index 1 is [b]Oargs index 2 is [c]OONIC:\T5Application1.exeI aEEEE bEE cNOargs lT^ is 3Oargs index 0 is [a]Oargs index 1 is [b]Oargs index 2 is [c]OONIC:\\T5Application1.exeI lT^ is 1Oargs index 0 is []OONIC:\T5Application1.exeI ILiteralE test INOargs lT^ is 1Oargs index 0 is [LiteralE test ]N

!?receives command-line arguments