| Start |
|---|
| Conditional Expressions When the following is compiled, it will return a different value depending on which directives are defined. Conditional expressions are typically used to log additional information for debug builds. |
Other Compiler Instructions Line
Pragma Checksum
|
| Defining and Undefining Symbols A compiler symbol is a keyword that is defined at compile-time that can be checked for to conditionally execute specific sections of code. There are three ways to define a compiler symbol. They can be defined via code: They can be defined in Visual Studio, under Project Properties > Build > Conditional Compilation Symbols: (Note that Or they can be defined at compile-time using the You can also undefined symbols using the The most prevalent example of this is the In the example above, when an error occurs in the business logic of the application, if the application is compiled in Debug mode (and the |
| Region Blocks Use These directives are only beneficial when an IDE that supports collapsible regions (such as Visual Studio (opens new window)) is used to edit the code. |
| Disabling and Restoring Compiler Warnings You can disable compiler warnings using Comma-separated warning numbers are allowed: The |
| Generating Compiler Warnings and Errors Compiler warnings can be generated using the |
| Using the Conditional attribute Adding a |
| Custom Preprocessors at project level It is convenient to set custom conditional preprocessing at project level when some actions need to be skipped lets say for tests. Go to Code example that will skip some code: Syntax
RemarksPreprocessor directives are typically used to make source programs easy to change and easy to compile in different execution environments. Directives in the source file tell the preprocessor to perform specific actions. For example, the preprocessor can replace tokens in the text, insert the contents of other files into the source file, or suppress compilation of part of the file by removing sections of text. Preprocessor lines are recognized and carried out before macro expansion. Therefore, if a macro expands into something that looks like a preprocessor command, that command is not recognized by the preprocessor. Preprocessor statements use the same character set as source file statements, with the exception that escape sequences are not supported. The character set used in preprocessor statements is the same as the execution character set. The preprocessor also recognizes negative character values. Conditional ExpressionsConditional expressions (
For example: would compile code that prints "OK!" to the console if Note: These substitutions are done at compile time and are therefore not available for inspection at run time. Code eliminated through use of See Also: C# Preprocessor Directives (opens new window) at MSDN. |
Read Article
https://develop.horje.com/learn/1434/reference