Method
System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform()
Possible Argument
OSPlatform.Windows
OSPlatform.OSX
OSPlatform.Linux
Example
bool isWindows = System.Runtime.InteropServices.RuntimeInformation
.IsOSPlatform(OSPlatform.Windows);
Update
Thanks to the comment by Oleksii Vynnychenko
You can get the operating systems name and version as a string using
var osNameAndVersion = System.Runtime.InteropServices.RuntimeInformation.OSDescription;
E.g. osNameAndVersion
would be Microsoft Windows 10.0.10586
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…