February 16, 2011

Pass command line arguments in C#

When running your console application if you  want to pass  certain command line arguments
From the Project menu choose Properties. Navigate to Debugging. Now you can see theCommand Line Arguments field in the right pane, as in the image below: enter something 




below is the code to fetch those arguments



using System;
using System.Collections.Generic;
using System.Text;


namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(args[0]);
            Console.WriteLine(args[1]);
        }
    }
}


and then start the program using ctrl+F5
Below 'll be the o/p



No comments:

Post a Comment