如何在C#中解析命令行参数

时间:2013-03-01 01:47:19

标签: c#

我正在尝试创建一个带有命令行参数(用户名和密码)的C#应用​​程序,并将它们都声明为变量,所以我会给Bob和12345提供参数,并将Bob保存为变量:Username和12345 as变量:密码。我该怎么做?

1 个答案:

答案 0 :(得分:4)

您可以使用Command Line Arguments执行此操作。

示例:

public static void Main(string[] args)
   {
       //The arguments are 0 and 1, for the first and second args.
       var username = args[0];
       var password = args[1];
   }