//CommandLine3.cs // Commandline arguments: A B C using System; namespace CommandLine3 { public class CommandLine3 { public static void Main(string[] args) { Console.WriteLine("You have entered the following {0} command line arguments:",args.Length); for (int i = 0; i < args.Length; i++) { Console.WriteLine("{0}", args[i]); } Console.ReadLine(); } } }Note that:
- The Length property is used to obtain the length of the array.
- Length is a read-only property
- Right-click the project(in the above example CommandLine3 will be the project) and click Properties this will open up Open the configuration Properties window and click Debugging tab.
- In the Command Line Arguments property, type "A B C" and save the project
- Run the project, make sure project has set as the startup project(to do this right click on the project and click on set as startup project
For running the code using command-line use following commands
- csc CommandLine.cs
- CommandLine.exe A B C
output
references : http://msdn.microsoft.com/
a simple command line argument program
ReplyDeletehttp://csharp.net-informations.com/overview/csharp-commandline-arguments.htm
ling.