如何将树简化if为 10 多个以添加运行文件的允许路径?代码是这样工作的 - 文件被传输到应用程序,应用程序确定文件路径及其名称,检查路径值是否等于指定的值。
ps 所有值if应该只导致一个else表单运行
static void Main(string[] args)
{
string filePath = args[1];
string fileName = Path.GetFileName(filePath);
string systemFolder = Environment.ExpandEnvironmentVariables("%SystemRoot%\\system32\\") + fileName;
string myFolder = Environment.ExpandEnvironmentVariables("%SystemDrive%\\my\\") + fileName;
if (filePath == systemFolder)
{
Process Proc = new Process();
Proc.StartInfo.Verb = "open";
Proc.StartInfo.FileName = fileName;
Proc.Start();
Application.Exit();
}
if (filePath == myFolder)
{
Process Proc = new Process();
Proc.StartInfo.Verb = "open";
Proc.StartInfo.FileName = fileName;
Proc.Start();
Application.Exit();
}
else
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
使用 OR 运算符 (||)