实现效果:

  判断驱动器类型并获其属性_编程

知识运用:

  DriveInfo类的DriveType属性  //获取驱动器类型

  public DriveType DriveType {get;}  /属性为枚举值之一

  判断驱动器类型并获其属性_编程_02

  DriveInfo类的VolumeLabel属性    //获取或设置驱动器卷标

  public string VolumeLabel {get ; set;}

实现代码:

        private void Form1_Load(object sender, EventArgs e)
        {
            DriveInfo[] drive = DriveInfo.GetDrives();
            foreach(DriveInfo d in drive)
            {
                ListViewItem item = new ListViewItem(d.Name);
                item.SubItems.Add(d.DriveType.ToString());
                item.SubItems.Add(d.VolumeLabel);
                item.SubItems.Add(d.DriveFormat);
                item.SubItems.Add((d.TotalFreeSpace/1024/1024/1024)+"G");
                item.SubItems.Add((d.TotalSize/1024/1024/1024)+"G");
                listView1.Items.Add(item);
            }
        }