RuntimeEnvironment 类
提供一个返回有关公共语言运行库环境的信息的 static 方法的集合。
**命名空间:**System.Runtime.InteropServices
**程序集:**mscorlib(在 mscorlib.dll 中)
语法
声明
<ComVisibleAttribute(True)> _
Public Class RuntimeEnvironment
用法
Dim instance As RuntimeEnvironment
[ComVisibleAttribute(true)]
public class RuntimeEnvironment
[ComVisibleAttribute(true)]
public ref class RuntimeEnvironment
/** @attribute ComVisibleAttribute(true) */
public class RuntimeEnvironment
ComVisibleAttribute(true)
public class RuntimeEnvironment
示例
此示例演示如何调用许多由 RuntimeEnvironment 类定义的方法。
using System;
using System.Reflection;
using System.Runtime.InteropServices;
public sealed class App
{
static void Main()
{
// Show whether the EXE assembly was loaded from the GAC or from a private subdirectory.
Console.WriteLine("Did the {0} assembly load from the GAC? {1}",
Assembly.GetExecutingAssembly(),
RuntimeEnvironment.FromGlobalAccessCache(Assembly.GetExecutingAssembly()));
// Show the path where the CLR was loaded from.
Console.WriteLine("Runtime directory: {0}", RuntimeEnvironment.GetRuntimeDirectory());
// Show the CLR's version number.
Console.WriteLine("System version: {0}", RuntimeEnvironment.GetSystemVersion());
// Show the path of the machine's configuration file.
Console.WriteLine("System configuration file: {0}", RuntimeEnvironment.SystemConfigurationFile);
}
}
// This code produces the following output.
//
// Did the RuntimeEnvironment, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// assembly load from the GAC? False
// Runtime directory: C:\WINDOWS\Microsoft.NET\Framework\v2.0.40607\
// System version: v2.0.40607
// System configuration file: C:\WINDOWS\Microsoft.NET\Framework\v2.0.40607\config\
// machine.config
using namespace System;
using namespace System::Reflection;
using namespace System::Runtime::InteropServices;
int main()
{
// Show whether the EXE assembly was loaded from the GAC or from a
// private subdirectory.
Console::WriteLine("Did the {0} assembly load from the GAC? {1}",
Assembly::GetExecutingAssembly(),
RuntimeEnvironment::FromGlobalAccessCache(
Assembly::GetExecutingAssembly()));
// Show the path where the CLR was loaded from.
Console::WriteLine("Runtime directory: {0}",
RuntimeEnvironment::GetRuntimeDirectory());
// Show the CLR's version number.
Console::WriteLine("System version: {0}",
RuntimeEnvironment::GetSystemVersion());
// Show the path of the machine's configuration file.
Console::WriteLine("System configuration file: {0}",
RuntimeEnvironment::SystemConfigurationFile);
}
// This code produces the following output.
//
// Did the RuntimeEnvironment, Version=0.0.0.0, Culture=neutral,
// PublicKeyToken=null
// assembly load from the GAC? False
// Runtime directory: C:\WINDOWS\Microsoft.NET\Framework\v2.0.40607\
// System version: v2.0.40607
// System configuration file:
// C:\WINDOWS\Microsoft.NET\Framework\v2.0.40607\config\machine.config
继承层次结构
System.Object
System.Runtime.InteropServices.RuntimeEnvironment
线程安全
此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。
平台
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