Use RuntimeInformation.IsOSPlatform.
Cross-platform .NET means the same binary runs on Windows, Linux and macOS. Detect the host OS:
```csharp
using System.Runtime.InteropServices;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) Console.WriteLine("Windows");
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) Console.WriteLine("Linux");
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) Console.WriteLine("macOS");
```Sign in to save your code and track progress across devices.