This site is 100% ad supported. Please add an exception to adblock for this site.

C# Preprocessor Directives

Terms

undefined, object
copy deck
How many preprocessor directives can appear on a single line.
One
What is the #if directive for?
The #if tests a conditional statement. If the statement evaluates to 'true' then all statements between the #if and #endif statements are compiled.
What comparison operators can be used with the #if directive?
==
!=
&&
||
What other preprocessor directives are used with #if?
#else
#elif
#endif
#define
#undef
What is the #else preprocessor directive used for?
The #else preprocessor directive is used to create an alternate compile path in the case that #if preprocessor directive evaluates to false.
What preprocessor directive must follow #else?
The #endif preprocessor directive must be the next preprocessor directive after #else.
What is the #elif directive used for?
The #elif preprocessor directive allow more complex compile stream logic to be expressed more simply than by nesting #if ... #else ... #endif sequences. #elif accepts that same operators that #if accepts. It must be nested within a #if ... #endif sequence. It is equivalent to using a #else ... #if sequence.
What is the #endif preprocessor directive used for?
The #endif preprocessor directive is used to terminate an #if block.
What is the #define preprocessor directive used for?
It is used to define a symbol that can be evaluated by the #if, #elif preprocessor directive. You can also use the [Conditional("foo")] attribute to control compilation.
What is the preprocessor directive #undef used for?
To undefine an existing symbol, typically defined using the /define compiler options.
What is the purpose of the #warning preprocessor directive?
The #warning preprocessor directive is used to output a message during the compile. Example:
#warning Node connections not yet tested.

For example.
What is the #error preprocessor directive used for?
The #error preprocessor directive is used to output an error message during the compile process.

#error this code section is not fully developed and should not be used.

For example.
What is the purpose of the #line preprocessor directive?
The #line preprocessor directive is used to assign a line number to the following line in the source code. It may also have "default" as an argument so that the line numbering is reset.
What is the purpose of the #region and #endregion preprocessor directives?
They are specific to the Visual Studio environment. They are used to create a block of code that can be expanded and collapsed. #region must be terminated by an #endregion preprocessor directive. Optionally the #region preprocessor directive may have be named. Example: #region myRegion for fun

Deck Info

14

permalink