Поделиться через


Interaction.IIf Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Returns one of two objects, depending on the evaluation of an expression.

Namespace:  Microsoft.VisualBasic
Assembly:  Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)

Syntax

'Declaration
Public Shared Function IIf ( _
    Expression As Boolean, _
    TruePart As Object, _
    FalsePart As Object _
) As Object
public static Object IIf(
    bool Expression,
    Object TruePart,
    Object FalsePart
)

Parameters

  • Expression
    Type: System.Boolean
    Required. Boolean. The expression you want to evaluate.
  • TruePart
    Type: System.Object
    Required. Object. Returned if Expression evaluates to True.
  • FalsePart
    Type: System.Object
    Required. Object. Returned if Expression evaluates to False.

Return Value

Type: System.Object
Returns one of two objects, depending on the evaluation of an expression.

Remarks

The IIf function provides a counterpart for the ternary conditional operator (?)in Visual C++.

Examples

This example uses the IIf function to evaluate the testMe parameter of the checkIt procedure and returns the word "Large" if the amount is greater than 1000; otherwise, it returns the word "Small".

Function checkIt(ByVal testMe As Integer) As String
    Return CStr(IIf(testMe > 1000, "Large", "Small"))
End Function

Note that if Option Strict is On, you must use the CStr keyword to explicitly convert the return from Object to String.

Version Information

Silverlight

Supported in: 5, 4, 3

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.