C# 将参数传递到具有特定格式c的控制台应用程序#
我想用这种特定格式将参数传递给c#控制台应用程序。 假设我的应用程序的exe名称是SmsSender, 我想在我的cmd中使用此格式: SmsSender-m消息-p电话号码C# 将参数传递到具有特定格式c的控制台应用程序#,c#,cmd,console,C#,Cmd,Console,我想用这种特定格式将参数传递给c#控制台应用程序。 假设我的应用程序的exe名称是SmsSender, 我想在我的cmd中使用此格式: SmsSender-m消息-p电话号码 我怎样才能做到这一点呢?您只需将该命令写入命令提示符窗口,就像您在其中所写的那样 在c#应用程序中有一个静态void Main(string[]args),args数组将有4个元素: args[0] = "-m"; args[1] = "message"; args[2] = "-p"; args[3] = "phonen
我怎样才能做到这一点呢?您只需将该命令写入命令提示符窗口,就像您在其中所写的那样 在c#应用程序中有一个
静态void Main(string[]args)
,args数组将有4个元素:
args[0] = "-m";
args[1] = "message";
args[2] = "-p";
args[3] = "phonenumber";
但是请注意,如果您没有在命令提示符中用“引号”括起邮件,那么邮件中的每个单词都将是args中的不同条目,请参阅此Microsoft文档 因此,在您的主方法中的控制台应用程序中,您将有如下内容:
class CommandLine
{
static void Main(string[] args)
{
// The Length property provides the number of array elements.
Console.WriteLine($"parameter count = {args.Length}");
// Get values using the `args` array in your case you will have:
// args[0] = "-m";
// args[1] = "message";
// args[2] = "-p";
// args[3] = "phonenumber";
for (int i = 0; i < args.Length; i++)
{
Console.WriteLine($"Arg[{i}] = [{args[i]}]");
}
}
}
类命令行
{
静态void Main(字符串[]参数)
{
//Length属性提供数组元素的数量。
WriteLine($“参数计数={args.Length}”);
//在您的情况下,使用'args'数组获取值您将拥有:
//args[0]=“-m”;
//args[1]=“消息”;
//args[2]=“-p”;
//args[3]=“电话号码”;
for(int i=0;i
请向我们展示您目前的尝试。