Environment.Version 屬性

定義

取得包含主要版本、次要版本、組建與 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

Common Language Runtime 的版本。

範例

下列範例會顯示 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
open System

printfn $"\nVersion: {Environment.Version}"
' 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 3.x 和 .NET 5+, Environment.Version 屬性會傳回 .NET 執行時間版本號碼。

針對 .NET Framework 4、4.5、4.5.1 和 4.5.2 版,Environment.Version 屬性會傳回 Version 物件,其字串表示的格式為 4.0.30319.xxxxx。 針對 .NET Framework 4.6 和更新版本,以及 3.0 之前的 .NET Core 版本,其格式 4.0.30319.42000 為 。

警告

對於 .NET Framework 4.5 和更新版本,我們不建議使用 Version 屬性來偵測執行時間的版本;相反地,您可以查詢登錄來判斷 Common Language Runtime 的版本。 如需詳細資訊,請參閱如何:判斷已安裝哪些.NET Framework版本

如需隨每個版本的 .NET Framework一起安裝的 Common Language Runtime 版本詳細資訊,請參閱版本和相依性

適用於