C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Const: We define the TEST constant at the top of the program with #Const. This is a compiler constant.
DirectivesResult: The TEST constant is defined, so the Conditional Sub is compiled and executed at runtime. The field is assigned the value 100.
VB.NET program that uses Conditional attribute
#Const TEST = 1
Module Module1
Dim _value As Integer
<Conditional("TEST")> Sub Test()
_value = 100
End Sub
Sub Main()
Test()
Console.WriteLine("VALUE IS {0}", _value)
End Sub
End Module
Output
VALUE IS 100
So: The Test() sub is never executed. The value is never set to 100, and it retains is default value of 0 at runtime.
VB.NET program that uses Conditional, not compiled
#Const TEST = 0
Module Module1
Dim _value As Integer
<Conditional("TEST")> Sub Test()
_value = 100
End Sub
Sub Main()
Test()
Console.WriteLine("VALUE IS {0}", _value)
End Sub
End Module
Output
VALUE IS 0
VB.NET program that uses Obsolete attribute
Module Module1
<Obsolete> Sub Test()
' Empty.
End Sub
Sub Main()
' The compiler will issue a warning if we call this obsolete Sub.
Test()
End Sub
End Module
Output
Warning BC40008
'Public Sub Test()' is obsolete.