1. Use C # To obtain the OS Version Number
(1) Principles
The OSVersion attribute of the Environment class is an OperatingSystem object. The OperatingSystem class indicates information about the operating system, such as the version and platform identifier. The OperatingSystem class Version attribute describes the main Version number, minor Version number, internal Version number, and corrected Version number of the operating system. Therefore, you can use Environment. OSVersion. Version to obtain the Version information of the operating system.
(2) specific code
Using System; namespace GetOSVersionExp {class Program {static void Main (string [] args) {Version currentVersion = Environment. OSVersion. version; // OS Version number Console. writeLine ("Major: {0}", currentVersion. toString (); // Console of the major OS version number. writeLine ("Major: {0}", currentVersion. major); // The minor version of the OS version number Console. writeLine ("Minor: {0}", currentVersion. minor); // Console of the OS version. writeLine ("Build: {0}", currentVersion. build); // OS version number revision part value Console. writeLine ("Revision: {0}", currentVersion. revision); // The 16-bit high Console of the OS version number. writeLine ("MajorRevision: {0}", currentVersion. majorRevision); // The 16-bit lower Console of the OS version number. writeLine ("MinorRevision: {0}", currentVersion. minorRevision );}}}
(3) program execution results
(4) supplementary instructions <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> Release + sOaxvrrF 08m2/tbBy8S49rK/release + release/release + w5rG + usW + release + dPQtqjS5bXE1 + m8/release + 8r9oaMKPHA + release/release + io6y /configure/HIobWxx7DV/configure + CjxwPs/Cw + a1xLT6wuvR3cq + wPvTw7e0yeS8vMr1u/HIobWxx7DV/configure + PHByZSBjbGFzcz0 = "brush: java; "> using System; using System. reflection; namespace GetOSVersionExp {class Program {static void Main (string [] args) {Assembly assem = Assembly. getExecutingAssembly (); AssemblyName assemName = assem. getName (); Version ver = assemName. version; Console. writeLine ("{0}, Version {1}", assemName. name, ver. toString ());}}}
Shows the execution result:
In the code, use the GetExecutingAssembly () method of the Assembly class to obtain the Assembly containing the Code being executed, and then use the GetName () method to obtain the Assembly name (represented by the object of the AssemblyName class ), and obtain the assembly Version information by accessing the attribute Version of AssemblyName. To use the Assembly class, you need to add reference "using System. Reflection ;".
3. Use C # To determine whether the current operating system is a Win8 System
Directly Add code
Using System; namespace GetOSVersionExp {class Program {static void Main (string [] args) {Version currentVersion = Environment. OSVersion. version; Version compareToVersion = new Version ("6.2"); if (currentVersion. compareTo (compareToVersion)> = 0) {// system Console of win8 and later versions. writeLine ("the current system is WIN8 or later. ");} Else {Console. WriteLine (" the current system is not WIN8 or a later version. ");}}}}
Run the program
Because the local computer is Windows 7, the program running result is "the current system is not Windows 8 or above ".
This method is applicable when determining whether the system is later than or earlier than a certain version. to accurately determine the type of the current system, refer to C # operating system type judgment summary.
Okay, that's it.