Chapter 21

Answers to Chapter 21 Review Questions

1: How can you make the code between #if and #endif of the following lines be included in the compilation
#if TRIALEDITION
    <Some code>
#endif
A1: By letting the following line be the first line in the source code:
#define TRIALEDITION
2: Is the second line in the following two lines of code valid? Why or why not?
using System;
#define
A2: No, it is invalid. #define and #undef must precede any non-preprocessor directives in the source code.
3: Add the necessary preprocessor directives and identifiers to the following lines of code, so that <Code part 1> is excluded from the compilation and <Code part 2> is included.
...
#if
    <Code part 1>
#endif
...
#if
    <Code part 2>
#endif
...
A3:
 #undef PART1 ...

Get C# Primer Plus now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.