First, when you create a new console application in the C# language using Visual Studio, you will get a Main method with a signature similar to the one shown here, ith a string[] args constant and abandoned acknowledgment type. You can use a Main adjustment that allotment an int or that receives no ambit if you wish to.
This program shows how the command-line parameters are received from a Windows command line and how you can access and test them in the C# program.
using System;
class Program
{
static void Main(string[] args)
{
if (args == null)
{
Console.WriteLine("args is null"); // Check for null array
}
else
{
Console.Write("args length is ");
Console.WriteLine(args.Length); // Write array length
for (int i = 0; i < args.Length; i++) // Loop through array
{
string argument = args[i];
Console.Write("args index ");
Console.Write(i); // Write index
Console.Write(" is [");
Console.Write(argument); // Write string
Console.WriteLine("]");
}
}
Console.ReadLine();
}
}
0 comments:
Post a Comment