Friday, March 5, 2010

Conditional Compilation

#define test = true
class TestClass {
void test() {
#if test
// do something
#else
// do something else
#endif
}}

Here's the equivalent code in VB.NET:

#Const test = True
Class TestClass
Sub test()
#If test
'do something
#Else
'do something else
#End If
End Sub
End Class

Here's the same but using the DEBUG constant which is automatically set by Visual Studio based on whether you are in debug mode:


Class TestClass
Sub test()
#If DEBUG
'do something
#Else
'do something else
#End If
End Sub
End Class

No comments: