Two Ways to Access Command Line in C
- 2021-07-03 00:46:19
- OfStack
This article illustrates two ways C # can access the command line. Share it for your reference. The details are as follows:
Method 1:
// Parameters: A B C
using System;
public class CommandLine
{
public static void Main(string[] args)
{
// Length Property is used to get the length of the array.
// Attention, Length Is a read-only property:
Console.WriteLine("Number of command line parameters = {0}", args.Length);
for(int i = 0; i < args.Length; i++)
{
Console.WriteLine("Arg[{0}] = [{1}]", i, args[i]);
}
}
}
Method 2:
// Parameters: John Paul Mary
using System;
public class CommandLine2
{
public static void Main(string[] args)
{
Console.WriteLine("Number of command line parameters = {0}", args.Length);
foreach(string s in args)
{
Console.WriteLine(s);
}
}
}
I hope this article is helpful to everyone's C # programming.