这篇文章主要为大家详细介绍了C#如何检测操作系统版本的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
这篇文章主要为大家详细介绍了C#如何检测操作系统版本的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
这篇文章主要为大家详细介绍了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 程序兼容性模式功能的版本相匹配的操作系统版本。
代码:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
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}} |
输出结果:

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持米米素材网。
发表评论