使用下面的代码,命令提示符在出现后几乎立即消失。此代码不应显示正在使用的所有可移动驱动器吗?
using System.Linq;
using System.IO;
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var drives = DriveInfo.GetDrives()
.Where(drive => drive.IsReady && drive.DriveType == DriveType.Removable);
Console.WriteLine("Removable drives being used:", drives);
}
}
}
非常感谢提前!
答案 0 :(得分:2)
最后尝试Console.ReadLine()
。一旦运行的应用程序终止,Windows就会关闭命令窗口。
答案 1 :(得分:2)
因为它执行你的命令并且存在。您可以在关闭前给它一个等待任何按键的指令。
例如:
Console.ReadKey();
更新:
using System.Linq;
using System.IO;
using System;
class Program
{
static void Main(string[] args)
{
DriveInfo[] drives = DriveInfo.GetDrives()
.Where(drive => drive.IsReady && drive.DriveType == DriveType.Removable);
foreach(DriveInfo di in drives)
{
Console.WriteLine("Removable drives being used:", di.Name);
{
}
}
答案 2 :(得分:1)
试试这个......
DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach(DriveInfo dv in drives)
{
Console.WriteLine("drive Name:{0}", dv.Name);
}
Console.ReadLine();