Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Conditional Compilation Overview

You can use conditional compilation to select particular sections of code to compile while excluding other sections. For example, you may want to write debugging statements that compare the speed of different approaches to the same programming task, or you may want to localize an application for multiple languages. Conditional compilation statements are designed to run during compile time, not at run time.

You declare a conditional compiler constant in code with the #Const directive, and you denote blocks of code to be conditionally compiled with the #If...Then...#Else directive. For example, to create French and German language versions of the same application from the same source code, you embed platform-specific code segments in #If...Then statements using the predefined constants FrenchVersion and GermanVersion. The following example demonstrates how:

#If FrenchVersion Then
   ' <code specific to the French language version>.
#ElseIf GermanVersion Then
   ' <code specific to the German language version>.
   ' <code specific to other versions>.
#End If

If you set the value of the FrenchVersion constant to True at compile time, the conditional code for the French version is compiled. If you set the value of the GermanVersion constant to True, the compiler uses the German version. If neither is set to True, the code in the last Else block runs.

Note   Autocompletion will not function when editing code and using conditional compilation directives if the code is not part of the current branch.

See Also

Declaring Conditional Compilation Constants | Collapsing and Hiding Sections of Code | Building from the Command Line | #Const Directive | #If...Then...#Else Directives

© 2017 Microsoft