Environment.Version 属性

定义

获取由公共语言运行时的主要版本号、次要版本号、内部版本号和修订号组成的版本。Gets a version consisting of the major, minor, build, and revision numbers of the common language runtime.

public:
 static property Version ^ Version { Version ^ get(); };
public static Version Version { get; }
member this.Version : Version
Public Shared ReadOnly Property Version As Version

属性值

Version

公共语言运行时的版本。The version of the common language runtime.

示例

下面的示例显示公共语言运行时的版本。The following example displays the version of the common language runtime.

// Sample for the Environment::Version property
using namespace System;
int main()
{
   Console::WriteLine();
   Console::WriteLine( "Version: {0}", Environment::Version );
}

/*
This example produces the following results:
(Any result that is lengthy, specific to the machine on which this sample was tested, or reveals information that should remain secure, has been omitted and marked S"!---OMITTED---!".)

Version: !---OMITTED---!
*/
// Sample for the Environment.Version property
using System;

class Sample
{
    public static void Main()
    {
    Console.WriteLine();
    Console.WriteLine("Version: {0}", Environment.Version.ToString());
    }
}
' Sample for the Environment.Version property
Class Sample
   Public Shared Sub Main()
      Console.WriteLine()
      Console.WriteLine("Version: {0}", Environment.Version.ToString())
   End Sub
End Class

注解

对于 .NET Core 2.x 和 .NET 5 +, Environment.Version 属性返回 .net 运行时版本号。For .NET Core 3.x and .NET 5+, the Environment.Version property returns the .NET runtime version number.

对于 .NET Framework 版本 4、4.5、4.5.1 和 4.5.2,Environment.Version 属性返回字符串表现形式具有窗体 4.0.30319.xxxxxVersion 对象。For the .NET Framework Versions 4, 4.5, 4.5.1, and 4.5.2, the Environment.Version property returns a Version object whose string representation has the form 4.0.30319.xxxxx. 对于4.6 和更高版本以及3.0 之前的 .NET Core 版本,其形式为 .NET Framework 4.0.30319.42000For the .NET Framework 4.6 and later versions, and .NET Core versions before 3.0, it has the form 4.0.30319.42000.

警告

对于 .NET Framework 4.5 及更高版本,我们不建议使用 Version 属性来检测运行时的版本; 相反,你可以通过查询注册表来确定公共语言运行时的版本。For the .NET Framework 4.5 and later, we do not recommend using the Version property to detect the version of the runtime; instead, you can determine the version of the common language runtime by querying the registry. 有关详细信息,请参阅 如何:确定安装了哪些 .NET Framework 版本For more information, see How to: Determine Which .NET Framework Versions Are Installed.

有关随每个版本的 .NET Framework 一起安装的公共语言运行时版本的详细信息,请参阅 版本和依赖项For more information about the version of the common language runtime that is installed with each version of the .NET Framework, see Versions and Dependencies.

适用于