Is it possible to do one line if statement in VB .NET? If so, how?
Is it possible to do one line if statement in VB .NET? If so, how?
Use IF().
It is a short-circuiting ternary operator.
Dim Result = IF(expression,<true return>,<false return>)
SEE ALSO:
At the risk of causing some cringing by purests and c# programmers, you can use multiple statements and else in a one-line if statement in VB. In this example, y ends up 3 and not 7.
i = 1
If i = 1 Then x = 3 : y = 3 Else x = 7 : y = 7
If (condition, condition_is_true, condition_is_false)
It will look like this in longer version:
If (condition_is_true) Then
Else (condition_is_false)
End If