Is it possible to do one line if statement in VB .NET? If so, how?
+3
A:
It's actually pretty simple..
If CONDITION Then ..INSERT CODE HERE..
Quintin Robinson
2009-04-21 06:29:04
And the Else part?
codeape
2009-04-21 06:37:35
You just put Else <some more code here> at the end.
Joey
2009-04-21 06:59:59
+1
A:
You can use the IIf function too:
CheckIt = IIf(TestMe > 1000, "Large", "Small")
Jon Limjap
2009-04-21 06:31:01
+5
A:
Use IF().
Dim Result = IF(expression,<true return>,<false return>)
SEE ALSO:
beach
2009-04-21 06:54:30
+2
A:
Be careful with the IIf opertor though - it is not always short-circuited and both the true and false expressions are evaluated.
Paul Alexander
2009-04-21 07:44:20
+1
A:
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
xpda
2009-07-28 04:54:57
Why go half way??? i = 1 : if i = 1 Then x = 3 : y = 3 Else x = 7 : y = 7
hamlin11
2009-07-29 22:52:36