gpt4 book ai didi

C# 分隔 args 参数

转载 作者:行者123 更新时间:2023-12-02 22:33:48 29 4
gpt4 key购买 nike

我有一个程序可以计算多个数字的阶乘。这些数字在 cmd 中作为参数传递:

factorial.exe 3 4 5

这将分别计算 3、4 和 5 的阶乘。该程序的早期版本有一个百分比显示堆栈的完整性。我现在想把它带回来,但我也将等待时间作为 cmd 中的参数传递:

factorial.exe 3 4 5 wait_time1

factorial.exe 3 4 5 1000

要读取数字,我使用这个 args 解析器:

static string the_time;
public static void Main(string[] args)
{

foreach (string s in args)
{

extra = int.Parse(s);

Calculate(extra);
}
}

如何分隔参数?提前致谢。

最佳答案

您可以像开关 /t:100 一样添加 waittime arg,因此只有当您看到 /t 时,您才知道它是一个 等待时间

如果你知道你的参数总是有waittime,那么waittime就是

waittime = arg[args.Length-1]

可能也值得一看

如果你不想重新发明轮子

关于C# 分隔 args 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11772561/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com