首页 > 编程技术 > csharp

C#访问命令行的两种方法

发布时间:2020-6-25 11:28

本文实例讲述了C#访问命令行的两种方法。分享给大家供大家参考。具体如下:

方法1:

// 参数:A B C
using System;
public class CommandLine
{
  public static void Main(string[] args)
  {
    // Length 属性用于获取数组的长度。
    // 注意,Length 是只读属性:
    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]);
    }
  }
}

方法2:

// 参数: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);
    }
  }
}

希望本文所述对大家的C#程序设计有所帮助。

标签:[!--infotagslink--]

您可能感兴趣的文章: