If a non-Boolean expression is used in the IF expression, the Vb.Net compiler converts the expression to Boolean using the method Conversions.ToBoolean.
Your code is equal
If Conversions.ToBoolean(StringValueContainingTrueOrFalse) then
'Do Something
End if
If your value can be converted to logical, everything will be fine. Otherwise, an exception will be thrown.
For instance:
Sub Main
Dim StringValueContainingTrueOrFalse as String = "True"
IF StringValueContainingTrueOrFalse then
Console.WriteLine("true")
end if
End Sub
The above program generates the following IL:
IL_0000: ldstr "True"
IL_0005: stloc.0 // StringValueContainingTrueOrFalse
IL_0006: ldloc.0 // StringValueContainingTrueOrFalse
IL_0007: call Microsoft.VisualBasic.CompilerServices.Conversions.ToBoolean
IL_000C: brfalse.s IL_0018
IL_000E: ldstr "true"
IL_0013: call System.Console.WriteLine
IL_0018: ret
You can see that the method call is shown on the label IL_0007 Conversions.ToBoolean.
source
share