IIF - Alternatives To IIf

Alternatives To IIf

In Visual Basic, IIf is not the sole way to evaluate and perform actions based on whether an expression is true or false.

The following example uses IIf:

result = IIf(x = y, value1, value2)

It could also be written in the following way, using standard conditionals:

If x = y Then result = value1 Else result = value2 End If

The above example would also eliminate the problem of IIf evaluating both its truepart and falsepart parameters.

Visual Basic 2008 (VB 9.0) introduced a true conditional operator, called simply "If", which also eliminates this problem. Its syntax is similar to the IIf function's syntax:

result = If(x = y, value1, value2)

Read more about this topic:  IIF

Famous quotes containing the words alternatives to and/or alternatives:

    The literal alternatives to [abortion] are suicide, motherhood, and, some would add, madness. Consequently, there is some confusion, discomfort, and cynicism greeting efforts to “find” or “emphasize” or “identify” alternatives to abortion.
    Connie J. Downey (b. 1934)

    The literal alternatives to [abortion] are suicide, motherhood, and, some would add, madness. Consequently, there is some confusion, discomfort, and cynicism greeting efforts to “find” or “emphasize” or “identify” alternatives to abortion.
    Connie J. Downey (b. 1934)