當前文章的短網址連結為: https://unos.top/fbdu
There are four preprocessor directives that control conditional compilation:
#if, #elif, #else, and #endif.
Code language: CSS (css)
You define symbols using #define, as shown in the following code:
#define MYSYMBOL
Many symbols are automatically defined for you, as shown in the following table:
Target Framework | Symbols |
.NET Standard | NETSTANDARD2_0, NETSTANDARD2_1, and so on |
Modern .NET | NET6_0, NET6_0_ANDROID, NET6_0_IOS, NET6_0_WINDOWS, and so on |
You can then write statements that will compile only for the specified platforms, as shown in the following code:
#if NET6_0_ANDROID // compile statements that only works on Android #elif NET6_0_IOS // compile statements that only works on iOS #else // compile statements that work everywhere else #endif