C# preprocessor differentiate between operating systems

Is it possible to differentiate between operating systems in C# using preprocessor? like :

#if OS_WINDOWS
//windows methods
#elif OS_MAC
//mac  methods
#elif OS_LINUX
//linux methods
#endif
Jon Skeet
people
quotationmark

No - think about it, the compiler runs once, but the same binary output can be used on multiple machines.

Now you can specify any symbols you want when you compile - so you could easily compile three different times and pass in different preprocessor symbols each time.

If you don't need any compile-time changes, you can just use Environment.OSVersion to detect the operating system you're running under.

people

See more on this question at Stackoverflow