Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 获取磁盘分区_C#_.net - Fatal编程技术网

C# 获取磁盘分区

C# 获取磁盘分区,c#,.net,C#,.net,我想让我的系统中的所有分区都可用。这段代码只返回一个分区 string[] arr = new string[4]; ListViewItem itm; DriveInfo[] allDrives = DriveInfo.GetDrives(); foreach (DriveInfo d in allDrives) { if (d.IsReady == true) { arr[0] = d.Name; arr[1] = d.DriveType.To

我想让我的系统中的所有分区都可用。这段代码只返回一个分区

string[] arr = new string[4];
ListViewItem itm;
DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo d in allDrives)
{
    if (d.IsReady == true)
    {
        arr[0] = d.Name;
        arr[1] = d.DriveType.ToString();
        arr[2] = d.TotalSize.ToString();
        arr[3] = d.DriveFormat;
        itm = new ListViewItem(arr);
        listView1.Items.Add(itm);
    }
}

我已经编辑了你的标题。请参阅“”,其中的共识是“不,他们不应该”。尝试使用。。。i、 e.
Directory.GetLogicalDrives()
该代码不返回任何分区。它返回一个磁盘驱动器。它不会返回未作为驱动器装入的分区。您的可能副本应每次创建一个新阵列,否则所有项目将显示相同的信息(即上一个驱动器的信息)