我知道有很多类似的问题/答案,但我无法根据自己的问题来调整解决方案:
我试图进行迭代,遍历列表框的项目(所有元素都是路径),我想通过单击按钮,使用默认的Windows程序将其全部打开。任何帮助将不胜感激。
问题是foreach
语句后的分号。分号立即结束foreach语句。您上面的代码等效于:
foreach (string myitem in this.listBox1.Items)
{
// myitem is only available in this scope
}
MessageBox.Show(myitem.toString(), "My Caption", MessageBoxButtons.OK, MessageBoxIcon.Information);
System.Diagnostics.Process.Start(myitem.ToString());
您需要将所需的所有内容封装在这样的范围内的foreach中:
foreach (string myitem in this.listBox1.Items)
{
MessageBox.Show(myitem.toString(), "My Caption", MessageBoxButtons.OK, MessageBoxIcon.Information);
System.Diagnostics.Process.Start(myitem.ToString());
}