我见过很多带参数的命令行程序,比如 ping google.com -t 。我怎样才能制作像ping这样的程序?我希望我的程序将一个数字作为参数,然后进一步使用这个数字:
例如:
geturi -n 1188
答案 0 :(得分:1)
只需编写一个通用的控制台应用程序。
主要方法如下所示:
class Program
{
static void Main(string[] args)
{
}
}
您的参数包含在args
数组中。
答案 1 :(得分:0)
使用普通的控制台应用程序,在static void Main(string[] args)
中,只需使用args
即可。如果您想将第一个参数作为数字读取,那么您只需使用:
static void Main(string[] args)
{
if (args.Length > 1)
{
int arg;
if (int.TryParse(args[0], out arg))
// use arg
else // show an error message (the input was not a number)
}
else // show an error message (there was no input)
}