
如果你想通过命令行传递参数,那么在C#中使用命令行参数 -
当我们在C#中创建程序时,使用static void main,我们可以看到其中的参数。
class HelloWorld {
static void Main(string[] args) {
/* my first program in C# */
Console.WriteLine("Hello World");
Console.ReadKey();
}string[] args 是一个变量,它包含从命令行传递的所有值,如上所示。
现在要打印这些参数,假设我们有一个参数“One” -
Console.WriteLine("Length of the arguments: "+args.Length);
Console.WriteLine("Arguments:");
foreach (Object obj in args) {
Console.WriteLine(obj);
}
上面将打印 -
Length of the arguments: 1 Arguments: One










