![](/img/trans.png)
[英]In C#, how do you get the name of an indexed property if you only have it's index number?
[英]How do you get a USB Drive's Name in C#?
我需要获取我的USB驱动器的名称。
假设我将USB驱动器重命名为“ ZeroErrors”。
它是驱动器号“ G:\\”,我想使用该驱动器号来获取USB驱动器的名称。
查看DriveInfo类。
string name = new DriveInfo("g").VolumeLabel;
或所有可移动驱动器:
DriveInfo.GetDrives()
.Where(x => x.DriveType == DriveType.Removable)
.Select(x => x.VolumeLabel)
以下代码可以解决问题:
DriveInfo drive = new DriveInfo("G:");
Console.WriteLine(drive.VolumeLabel);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.