#12 – Read Command Line Arguments
June 29, 2010 3 Comments
If you are calling your C# program from the command line, you can pass in one or more command line arguments. In your program, you can access these arguments by defining the Main function to accept a string array as a parameter and then iterating through the array to read the parameters.
static void Main(string[] args) { // Ex 1: List all arguments foreach (string arg in args) Console.WriteLine(string.Format("Arg: [{0}]", arg)); // Ex 2: Use 1st argument as filename if (args.Length > 0) Console.WriteLine(string.Format("File={0}", args[0])); }
Hey, Where this files’s are created by default? Or its just showing not creating any file ?
This example is saying that you could pass a filename in as the first parameter and then do something with it. But the example just displays the value of the 1st argument.
it’s a lame question plz delete that 🙂