Command Line Argument


This program describe the concept of command line argument. How to pass  values to the string array that is pass as parameter in the Main method. One thing that is important to describe is that we can just only create an array of string type in the Main method. If we try to make an array of char or int in the Main method then we get an error.

How to pass values to the command line arguments
Compilation is the same as in the earlier program  : -  csc CommandLineArg.cs
But when you would like to run the pass the parameter like :- CommandLineArg Amit Gopal Rohan Sohan

--------------------------------------------------------------------------------------------
using System;

class CommandLineArg
{
public static void Main(string[] str)
{
int length = str.Length; // Get the length of the string array.

Console.WriteLine("Total number of entered string is "+ length);


for(int i=0;i<str.Length;i++)
{
Console.WriteLine("The value at str[{0}] is {1}",i,str[i]);
}

}
}

-------------------------------------------------------------------------------------------


Command Line Argument Command Line Argument Reviewed by Baljeet Singh on 08:35 Rating: 5

No comments:

Powered by Blogger.