C# preprocessor differentiate between operating systems

前端 未结 3 1381
甜味超标
甜味超标 2020-12-31 05:21

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

#if OS_WINDOWS
//windows methods
#elif O         


        
3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-31 06:03

    What you are asking for is possible but needs a bit of work.

    1. Define a preprocessor variable in your csproj

      
        _WINDOWS
      
      
    2. Use that in your code

      #if _WINDOWS
        // your windows stuff
      #else
        // your *nix stuff
      #endif
      

    I find this technique useful when you have constants that are dependent on the OS (for example native library names)

提交回复
热议问题