作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在使用以下代码获取计算机上每个驱动器的盘符列表。我想从此列表中获取 CD 驱动器的盘符。如何检查?
我用来获取列表的代码如下:
在 Form.Load
事件中:
cmbDrives.DropDownStyle = ComboBoxStyle.DropDownList
Dim sDrive As String, sDrives() As String
sDrives = ListAllDrives()
For Each sDrive In sDrives
Next
cmbDrives.Items.AddRange(ListAllDrives())
...
Public Function ListAllDrives() As String()
Dim arDrives() As String
arDrives = IO.Directory.GetLogicalDrives()
Return arDrives
End Function
最佳答案
经过测试,并在我的计算机上返回了正确的结果:
Dim cdDrives = From d In IO.DriveInfo.GetDrives() _
Where d.DriveType = IO.DriveType.CDRom _
Select d
For Each drive In cdDrives
Console.WriteLine(drive.Name)
Next
当然假设是 3.5,因为它使用的是 LINQ。要填充列表框,请将 Console.WriteLine 更改为 ListBox.Items.Add。
关于.net - 在 VB.NET 中获取 CD 盘符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5281202/
我是一名优秀的程序员,十分优秀!