using System.IO; using System.Diagnostic; void Run(string fileA,string fileB) { if(Directory.Exists("I:\\") Process.Start(fileA); else Process.Start(fileB); }
这样的代码让我很不解! 拿一个bool值跟另一个bool值做比较有意义吗?
DriveInfo[] allDrives = DriveInfo.GetDrives(); foreach (DriveInfo d in allDrives) { if (d.Name.StartsWith("D")) { MessageBox.Show("A function"); break; } else MessageBox.Show("B Function"); } 这个做参考
你的方法 OK 只是 using System.Diagnostic; 少了个字母 using System.Diagnostics;
下面代码是获取所有盘符:namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); string[] dir = new string[10]; dir = Directory.GetLogicalDrives(); for (int i = 0; i < dir.Length; i++) { textBox1.Text += dir[i] + "\r\n"; } } } }
至于判断某个程序是否在运行,那就要检查A进程是否存在了。
using System.IO;
using System.Diagnostic;
void Run(string fileA,string fileB)
{
if(Directory.Exists("I:\\")
Process.Start(fileA);
else
Process.Start(fileB);
}
这样的代码让我很不解!
拿一个bool值跟另一个bool值做比较有意义吗?
DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo d in allDrives)
{
if (d.Name.StartsWith("D"))
{
MessageBox.Show("A function");
break;
}
else MessageBox.Show("B Function");
}
这个做参考
只是
using System.Diagnostic; 少了个字母
using System.Diagnostics;
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
string[] dir = new string[10];
dir = Directory.GetLogicalDrives();
for (int i = 0; i < dir.Length; i++)
{
textBox1.Text += dir[i] + "\r\n";
}
}
}
}