gpt4 book ai didi

c# - 传递枚举命令行参数

转载 作者:行者123 更新时间:2023-11-30 14:14:34 25 4
gpt4 key购买 nike

所以我有这个开关来设置等待时间

public int Option(string arg)
{
switch (arg)
{
case "/t:Max":
return 0;
case "/t:Med":
return 1000;
case "/t:Min":
return 2000;
default: return 0;
}
}

如何使用/t:Min、/t:Med、/t.Max 枚举来替换开关?

确实是这样的:

enum t
{
/t:Min,
/t:Med,
/t:Max
};

最佳答案

你的枚举应该是这样的:

public enum WaitTime 
{
Min, Max, Med
}

并将您的开关转换为:

switch ((WaitTime)Enum.Parse(typeof(WaitTime), arg.Replace("/:", string.Empty)))
{
case WaitTime.Max:
return 0;
case WaitTime.Med:
return 1000;
case WaitTime.Min:
return 2000;
default:
return 0;
}

关于c# - 传递枚举命令行参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11778564/

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