Environment.GetLogicalDrives Metoda

Definice

Vrátí pole řetězce obsahující názvy logických jednotek v aktuálním počítači.

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

Návraty

String[]

Pole řetězců, kde každý prvek obsahuje název logické jednotky. Pokud je například pevný disk počítače prvním logickým diskem, vrátí se první prvek C:\.

Výjimky

Dojde k vstupně-výstupní chybě.

Volající nemá požadovaná oprávnění.

Příklady

Následující příklad ukazuje, jak zobrazit logické jednotky aktuálního počítače pomocí GetLogicalDrives metody.

// 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:\
'

Platí pro