OneStopTesting.com - Testing EBooks, Tutorials, Articles, Jobs, Training Institutes etc.
OneStopGate.com - Gate EBooks, Tutorials, Articles, FAQs, Jobs, Training Institutes etc.
OneStopMBA.com - MBA EBooks, Tutorials, Articles, FAQs, Jobs, Training Institutes etc.
OneStopIAS.com - IAS EBooks, Tutorials, Articles, FAQs, Jobs, Training Institutes etc.
OneStopSAP.com - SAP EBooks, Tutorials, Articles, FAQs, Jobs, Training Institutes etc.
OneStopGRE.com - of GRE EBooks, Tutorials, Articles, FAQs, Jobs, Training Institutes etc.
Passing the Command Line Arguments in .NET | Articles | Recent Articles | News Article | Interesting Articles | Technology Articles | Articles On Education | Articles On Corporate | Company Articles | College Articles | Articles on Recession
Home » Articles » Passing the Command Line Arguments in .NET
Passing the Command Line Arguments in .NET
Article Posted On Date : Thursday, March 22, 2012
Passing the Command Line Arguments in .NET
Advertisements
Even with modern UI, we often need a way to start our programs with specific parameters. Command line arguments are helpful to provide those parameters without exposing them to everybody. When developing with .NET and C# you can get the command line arguments from your Main(string[] Args) function. Args is in fact an array containing all the strings separated by spaces entered in the command line. Suppose we have an application which accepts some command line parameters to do some operations. We know how to pass the parameters from command prompt. I havea sample here. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication2010 { class CommandLineArgument { static void Main(string[] arguments) { foreach (String arg in Environment.GetCommandLineArgs()) { Console.Write(arg); } Console.ReadKey(); } } } Now I am going to introduce passing the command line arguments from Visual Studio. Some times we don't like to pass the arguments from the Command Prompt. Here is a Quick way to pass the arguments. Visual Studio enables a nice feature where you can do this in the Project Properties window, on the Debug tab. Here is the steps to achieve this Right Click on Project from Solution Explorer and Select Properties. In the Project Properties Windows, Navigate to "Debug Tab" You will Find the a text box "Command Line". Please separate the arguments with the comma(',') or Space also. Here the Screen Shot to pass the arguments Here the source code follows : using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication2010 { class CommandLineArgument { static void Main(string[] arguments) { foreach (String arg in arguments) { Console.Write(arg); } Console.Write("Waiting for User response..."); Console.ReadKey(); } } } Here I put the break point to give the clear view of the arguments passed from the Debug Tab.
Amazon.in Widgets