Classes you didn’t know about: System.OperatingSystem
Posted: (EET/GMT+2)
If you are only developing applications for the Windows platform with .NET, you might not have noticed that there has been a class since the early days of .NET: the sealed class System.OperatingSystem.
This class allows you to read "information about an operating system, such as the version and platform identifier", as explained in the documentation.
The features of this class have grown steadily over the years to support new operating environments for .NET applications. If you are developing for .NET Framework, this class is limited in its features (properties and methods), but in .NET Core, new features allow you to detect for example if you are running under Linux or Windows.
On the .NET Framework, this class doesn't have any static properties, so you can use the System.Environment.OSVersion property to access a ready-initialized instance of this class.
On .NET Core, you can simply say things like OperatingSystem.IsWindows() and OperatingSystem.IsLinux(), depending on your needs.
The OperatingSystem class is a fine example of classes that have existed for over 20 years, but you might not have any need for them directly.
Happy hacking!