Passing Command Line Arguments Using VS 2010

Command line arguments are helpful to provide those parameters without exposing them to everybody.




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 the application which accepts some command line parameters to do some operations.We know how to pass the parameters from command prompt.I have that also some 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 the 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 features where you can do this in the Project Properties window, on the Debug tab. Here is the steps to achieve this
1. Right Click on Project from Solution Explorer and Select Properties.
2. In the Project Properties Windows, Navigate to “Debug Tab”
3. 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("\nWaiting for User response...");
           Console.ReadKey();
        }
     }
}

Here I put the break point to give the clear view of the arguments passed from the Debug Tab.


The final output is shown here

I thought this article would be helpful to the all. Any suggestions  are welcome.

Happy Coding :-)

Popular posts from this blog

Exporting to excel from a custom class object using C#.NET

Get the Clicked Cell Value and Column Name of GridView in ASP.NET

How to apply watermark to the textbox and dropdownlist?