Conditional Compilation in VB.NET
Conditional compilation is useful when you need to make some code available based on some conditions.
Conditional compilation is useful when you need to make some code available based on some conditions and code snippet in Listing 4 places three statements in a single line. Sometimes for testing purposes or debug purposes, you only want to run certain line of code only when debugging the application. We can simply have a conditional directive and make it true only in case of debugging and make it false one application is all tested.
The class listed in Listing 5 has two constants DEBUG and TESTING. When value of these directives is True, then only Enabled method will be available.
Public Class ConditionalCompilationClass
#Const DEBUG = False
#Const TESTING = False
#If DEBUG Then
Console.WriteLine("Debuging Enabled. ")
Console.WriteLine("Debuging Disabled. ")
#If TEST Then
Console.WriteLine("Testing Enabled. ")
Console.WriteLine("Testing Disabled. ")
Since value of these directives is false, if you create an instance of ConditionalCompilationClass, you will see only two Disabled methods are available in Intellisense. See Figure 1.