C#如何检测 *** 作系统版本

C#如何检测 *** 作系统版本,第1张

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

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

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

Version 类的属性

参考于:https://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#如何检测 *** 作系统版本全部内容,希望文章能够帮你解决C#如何检测 *** 作系统版本所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1257106.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-07
下一篇 2022-06-07

发表评论

登录后才能评论

评论列表(0条)

保存