操作系统 百分网手机站

C#检测操作系统版本的方法

时间:2020-11-14 18:58:09 操作系统 我要投稿

C#检测操作系统版本的方法汇总

  本文实例为大家分享了C#检测操作系统版本的方法,供大家参考,具体内容如下

  我们通过System.Environment.OSVersion.Version获得操作系统的`版本号,然后再根据版本号进行判断操作系统是什么版本。

  Version 类的属性

  参考于:http://msdn.microsoft.com/zh-cn/library/windows/desktop/ms724834(v=vs.85).aspx

  注意:在msdn官方文档有说明 → OSVersion 属性报告两个相同的版本号 (6.2.0.0) 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){this.OSystemName = oSystemName;}public GetOSystem(){switch (System.Environment.OSVersion.Version.Major + "." + System.Environment.OSVersion.Version.Minor){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("Windows8.OrWindows8.1");break;case Windows10:setOSystemName("Windows10");break;}Console.WriteLine(OSystemName);}}class Program{static void Main(string[] args){#region 检测系统new GetOSystem();#endregion}}

  输出结果:

  以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

【C#检测操作系统版本的方法汇总】相关文章:

1.获取当前操作系统的软件版本

2.关于Linux查看系统版本的方法汇总

3.KMP算法的C#实现方法

4.操作系统打补丁的方法

5.快速安装操作系统的方法

6.操作系统打补丁的方法

7.安装电脑的操作系统的方法

8.unix操作系统关机方法