This example for you to share the C # Detection of operating system version of the method for your reference, the specific content as follows
We obtained the version number of the operating system through System.Environment.OSVersion.Version and then judged what version of the operating system was based on the version number.
Properties of the Version class
Reference to: https://msdn.microsoft.com/zh-cn/library/windows/desktop/ms724834 (v=vs.85). aspx
Note: The MSDN official documentation has instructions for the →osversion Property report two identical version numbers (6.2.0.0) for Windows 8 and Windows 8.1. In some cases, the OSVersion property may not return an operating system version that matches the version of the specified Windows Program compatibility mode feature.
Code:
public class Getosystem {Private Const string Windows2000 = "5.0"; Private const string Windows XP = "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 Windows XP:
Setosystemname ("Windows XP");
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 detection System new Getosystem (); #endregion}}
Output results:
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.