Редагувати

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


Interaction.IIf(Boolean, Object, Object) Method

Definition

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

public:
 static System::Object ^ IIf(bool Expression, System::Object ^ TruePart, System::Object ^ FalsePart);
public static object? IIf (bool Expression, object? TruePart, object? FalsePart);
public static object IIf (bool Expression, object TruePart, object FalsePart);
static member IIf : bool * obj * obj -> obj
Public Function IIf (Expression As Boolean, TruePart As Object, FalsePart As Object) As Object

Parameters

Expression
Boolean

Required. Boolean. The expression you want to evaluate.

TruePart
Object

Required. Object. Returned if Expression evaluates to True.

FalsePart
Object

Required. Object. Returned if Expression evaluates to False.

Returns

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

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.

Remarks

The IIf function provides a counterpart for the ternary Conditional Operator: ? : in Visual C++.

Applies to

See also