如何比较列表框项与数组项
本文关键字:数组 列表 何比较 比较 | 更新日期: 2023-09-27 17:50:23
我有一个复选框,其中包含一些exe/应用程序名称。当我要选择其中任何一个时,它就会启动。现在应用程序正在启动,但如果我从路径中不存在的复选框中选择了exe/应用程序名称(我在下面写的),即如何对其进行验证。我的代码是:
if (chkListBox.CheckedItems.Count > 0)
{
for (int i = 0; i < chkListBox.CheckedItems.Count; i++)
{
string path = @"D:'Development'Latest'ConsoleApplication1'ConsoleApplication1'bin'Debug";
string files = Directory.GetDirectoryRoot(path);
var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = Path.Combine(path, chkListBox.Items[i].ToString() + ".exe")
}
};
process.StartInfo.UseShellExecute = false;// Beacuse I am using Process class
process.StartInfo.CreateNoWindow = true;
process.Start();
}
}
else
{
MessageBox.Show("Item Not selected");
}
string path = @"D:'Development'Latest'ConsoleApplication1'ConsoleApplication1'bin'Debug";
string files = Directory.GetDirectoryRoot(path);
var exeNotFoundList = new List<string>();
for (int i = 0; i < chkListBox.CheckedItems.Count; i++)
{
var exeFilePathWithName = Path.Combine(path, chkListBox.Items[i].ToString() + ".exe");
if(!File.Exists(exeFilePathWithName))
{
exeNotFoundList.Add(exeFilePathWithName);
continue;
}
var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = exeFilePathWithName
}
};
process.StartInfo.UseShellExecute = false;// Beacuse I am using Process class
process.StartInfo.CreateNoWindow = true;
process.Start();
}
if(exeNotFoundList.Count > 0)
{
var errorMessage = String.Join(String.Empty, exeNotFoundList.ToArray());
MessageBox.Show(errorMessage);
}