糯米文學吧

位置:首頁 > 計算機 > 操作系統

C#檢測操作系統版本的方法彙總

本文實例為大家分享了C#檢測操作系統版本的方法,供大家參考,具體內容如下

C#檢測操作系統版本的方法彙總

我們通過ion獲得操作系統的版本號,然後再根據版本號進行判斷操作系統是什麼版本。

Version 類的屬性

參考於:(v=vs.85)

注意:在msdn官方文檔有説明 → OSVersion 屬性報告兩個相同的版本號 () Windows 8 和 Windows 8.1。在某些情況下, OSVersion 屬性可能不會返回與指定的' Windows 程序兼容性模式功能的版本相匹配的操作系統版本。

代碼:

public class GetOSystem{private const string Windows2000 = "5.0";private const string WindowsXP = "5.1";private const string Windows2003 = "5.2";private const string Windows2008 = "6.0";private const string Windows7 = "6.1";private const string Windows8OrWindows81 = "6.2";private const string Windows10 = "10.0";private string OSystemName;public void setOSystemName(string oSystemName){temName = oSystemName;}public GetOSystem(){switch (r + "." + r){case Windows2000:setOSystemName("Windows2000");break;case WindowsXP:setOSystemName("WindowsXP");break;case Windows2003:setOSystemName("Windows2003");break;case Windows2008:setOSystemName("Windows2008");break;case Windows7:setOSystemName("Windows7");break;case Windows8OrWindows81:setOSystemName("ndows8.1");break;case Windows10:setOSystemName("Windows10");break;}eLine(OSystemName);}}class Program{static void Main(string[] args){#region 檢測系統new GetOSystem();#endregion}}

輸出結果:

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持。