站点图标 神之眼的博客

In NET 6, to handle different platforms is to use conditional compilation statements

當前文章的短網址連結為: 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 FrameworkSymbols
.NET StandardNETSTANDARD2_0, NETSTANDARD2_1, and so on
Modern .NETNET6_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
退出移动版