![]() ![]() The following code is compiled when MYTEST is not defined: #if !MYTESTĬonsole.WriteLine("MYTEST is not defined") For example, the following code is compiled when DEBUG is defined: #if DEBUG ![]() ![]() The #if statement in C# is Boolean and only tests whether the symbol has been defined or not. Unlike C and C++, a numeric value to a symbol can't be assigned. The C# compiler compiles the code between the #if directive and #endif directive only if the specified symbol is defined, or not defined when the ! not operator is used. #endif: Closes the preceding conditional compilation.#else: Closes the preceding conditional compilation and opens a new conditional compilation if the previous specified symbol isn't defined.#elif: Closes the preceding conditional compilation and opens a new conditional compilation based on if the specified symbol is defined.#if: Opens a conditional compilation, where code is compiled only if the specified symbol is defined.You use four preprocessor directives to control conditional compilation: #nullable restore warnings: Restores the nullable warning context to project settings.#nullable enable warnings: Sets the nullable warning context to enabled.#nullable disable warnings: Sets the nullable warning context to disabled.#nullable restore annotations: Restores the nullable annotation context to project settings.#nullable enable annotations: Sets the nullable annotation context to enabled.#nullable disable annotations: Sets the nullable annotation context to disabled.#nullable restore: Restores the nullable annotation and warning contexts to project settings.#nullable enable: Sets the nullable annotation and warning contexts to enabled.#nullable disable: Sets the nullable annotation and warning contexts to disabled.The effect of the directives is as follows: A directive sets the context(s) it controls until another directive overrides it, or until the end of the source file. The #nullable directive controls the annotation and warning contexts and takes precedence over the project-level settings. Each context is either disabled or enabled.īoth contexts can be specified at the project level (outside of C# source code). This directive controls whether nullable annotations have effect, and whether nullability warnings are given. The #nullable preprocessor directive sets the nullable annotation context and nullable warning context. A preprocessor directive must be the only instruction on a line. Unlike C and C++ directives, you can't use these directives to create macros. You use them to help in conditional compilation. Although the compiler doesn't have a separate preprocessor, the directives described in this section are processed as if there were one. ![]()
0 Comments
Leave a Reply. |