We all know that VB\'s Nothing
is similar, but not equivalent, to C#\'s null
. (If you are not aware of that, have a look at this answer first.)
You can create one yourself (pick a different name for the function if you like):
Private Function ValueOrNull(expression As Boolean, value As Object) As Object
If expression Then Return value
Return Nothing
End Function
Usage:
Dim myBool As Boolean
Dim o As Object = ValueOrNull(myBool, 5)
Works with any type, including your example with 5.0
.