Saturday, December 03, 2011

Command Line Arguments: Sample 1

Sample for Console Application with Command line arguments

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Args count:" + args.Length.ToString());
        foreach (string arg in args)
            Console.WriteLine("\t" + arg);
    }
}

Sample outputs

MyApps>CmdLineApp.exe
Args count:0

MyApps>CmdLineApp.exe Hello World
Args count:2
        Hello
        World

MyApps>CmdLineApp.exe "Hello World" Command line application
Args count:4
        Hello World
        Command
        line
        application

MyApps>CmdLineApp.exe "Hello World" "Command line application"
Args count:2
        Hello World
        Command line application

No comments:

Post a Comment