One line if in VB .NET

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:

  • IIF becomes If, and a true ternary operator

  • Is there a conditional ternary operator in VB.NET?

  • Orcas introduces the IF operator - a new and improved IIF

  • The Ternary Operator in VB.NET


  • 这其实很简单..

    If CONDITION Then ..INSERT CODE HERE..
    

    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
    
    链接地址: http://www.djcxy.com/p/42846.html

    上一篇: 如果在aspx页面中使用eval,则使用if

    下一篇: 一行,如果在VB .NET中