Environment.GetLogicalDrives 方法

定义

返回包含当前计算机中的逻辑驱动器名称的字符串数组。

public:
 static cli::array <System::String ^> ^ GetLogicalDrives();
public static string[] GetLogicalDrives ();
static member GetLogicalDrives : unit -> string[]
Public Shared Function GetLogicalDrives () As String()

返回

String[]

字符串数组,其中的每个元素都包含逻辑驱动器名称。 例如,如果计算机的硬盘是第一个逻辑驱动器,则返回的第一个元素是“C:\”。

例外

出现 I/O 错误。

调用方没有所需的权限。

示例

以下示例演示如何使用 GetLogicalDrives 该方法显示当前计算机的逻辑驱动器。

// Sample for the Environment::GetLogicalDrives method
using namespace System;
int main()
{
   Console::WriteLine();
   array<String^>^drives = Environment::GetLogicalDrives();
   Console::WriteLine( "GetLogicalDrives: {0}", String::Join( ", ", drives ) );
}

/*
This example produces the following results:

GetLogicalDrives: A:\, C:\, D:\
*/
// Sample for the Environment.GetLogicalDrives method
using System;

class Sample
{
    public static void Main()
    {
    Console.WriteLine();
    String[] drives = Environment.GetLogicalDrives();
    Console.WriteLine("GetLogicalDrives: {0}", String.Join(", ", drives));
    }
}
/*
This example produces the following results:

GetLogicalDrives: A:\, C:\, D:\
*/
// Sample for the Environment.GetLogicalDrives method
open System

let drives = Environment.GetLogicalDrives()

String.concat ", " drives
|> printfn "\nGetLogicalDrives: %s" 
// This example produces the following results:
//     GetLogicalDrives: A:\, C:\, D:\
' Sample for the Environment.GetLogicalDrives method
Class Sample
   Public Shared Sub Main()
      Console.WriteLine()
      Dim drives As [String]() = Environment.GetLogicalDrives()
      Console.WriteLine("GetLogicalDrives: {0}", [String].Join(", ", drives))
   End Sub
End Class
'
'This example produces the following results:
'
'GetLogicalDrives: A:\, C:\, D:\
'

适用于