1

I want to get the current MAC OS X Version using C#. There is a way to do it using a C# function?

I know the command sw_vers can do it, buy I prefer to avoid run a command if it is not necessary. What I need is a string like "10.4" or "10.6" or whatever.

This code:

Environment.OSVersion.ToString();

returns:

Unix 12.5.0.0 

But not 10.X that are the version numbers of mac releases

dhalfageme
  • 1,444
  • 4
  • 21
  • 42
  • Did you check the [Related questions](http://stackoverflow.com/q/6331826/238902)? (They are found to the right) – default Jan 21 '15 at 14:55
  • I can't find anything there. The solution they propose doesn't give me the version name (10.8) that the sw_vers command gives me – dhalfageme Jan 21 '15 at 15:09

1 Answers1

4

You should use Environment.OSVersion and to get the version Environment.OSVersion.Version

The returned version is the Darwin Kernel-Version (base of OS X). You have to map this to the OS X version, see the table under: Release history

BendEg
  • 20,098
  • 17
  • 57
  • 131
  • But this gives me a number like 4.0.XXXX.XXXX,. I want to map then the 10.X number with the version name (if I can get the version name, even better) – dhalfageme Jan 21 '15 at 14:52
  • Would you like to post your current code and result? – BendEg Jan 21 '15 at 14:54
  • Yes, posted. Sorry, previously I was using Environment.Version, not OSVersion. But this gives me 12.5, and the Mac versions start with 10, do not? – dhalfageme Jan 21 '15 at 15:01