Better way to get osversion?

  • Thread starter Thread starter William Stacey
  • Start date Start date
W

William Stacey

Is there a better way to get a double (or other) for os version then this?
I want to get os version early in program,
then do checks like: if ( osVersion < 5.2 ) //do something. TIA

int major = Environment.OSVersion.Version.Major;
int minor = Environment.OSVersion.Version.Minor;
try
{
double dver = Double.Parse(major.ToString() + "." + minor.ToString());
return dver;
}
catch
{
//Do something;
}
 
You could just use the Version as is:

For example:

Version targetVersion = new Version(5, 2);
Version osVersion = Environment.OSVersion.Version;

if ( osVersion < targetVersion ) {
}

Note this will be more precise and can take into account builds and revion
numbers as well.
 
Thanks Justin.

--
William Stacey, MVP

Justin Rogers said:
You could just use the Version as is:

For example:

Version targetVersion = new Version(5, 2);
Version osVersion = Environment.OSVersion.Version;

if ( osVersion < targetVersion ) {
}

Note this will be more precise and can take into account builds and revion
numbers as well.
 
Back
Top