Environment.GetLogicalDrives 方法
返回包含当前计算机中的逻辑驱动器名称的字符串数组。
**命名空间:**System
**程序集:**mscorlib(在 mscorlib.dll 中)
语法
声明
Public Shared Function GetLogicalDrives As String()
用法
Dim returnValue As String()
returnValue = Environment.GetLogicalDrives
public static string[] GetLogicalDrives ()
public:
static array<String^>^ GetLogicalDrives ()
public static String[] GetLogicalDrives ()
public static function GetLogicalDrives () : String[]
返回值
字符串数组,其中的每个元素都包含逻辑驱动器名称。例如,如果计算机的硬盘是第一个逻辑驱动器,则返回的第一个元素是“C:\”。
异常
异常类型 | 条件 |
---|---|
发生 I/O 错误。 |
|
调用方没有所需的权限。 |
示例
' Sample for the Environment.GetLogicalDrives method
Imports System
Class Sample
Public Shared Sub Main()
Console.WriteLine()
Dim drives As [String]() = Environment.GetLogicalDrives()
Console.WriteLine("GetLogicalDrives: {0}", [String].Join(", ", drives))
End Sub 'Main
End Class 'Sample
'
'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
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
import System.*;
class Sample
{
public static void main(String[] args)
{
Console.WriteLine();
String drives[] = Environment.GetLogicalDrives();
Console.WriteLine("GetLogicalDrives: {0}", String.Join(", ", drives));
} //main
} //Sample
/*
This example produces the following results:
GetLogicalDrives: A:\, C:\, D:\
*/
.NET Framework 安全性
- EnvironmentPermission 用于完全访问受此权限保护的资源。关联的枚举:PermissionState.Unrestricted
平台
Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0