Interaction.IIf(Boolean, Object, Object) 方法

定義

根據運算式的評估結果,傳回兩個物件當中的其中一個。

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

參數

Expression
Boolean

必要。 Boolean. 要評估的運算式。

TruePart
Object

必要。 Object. 在 Expression 評估為 True 時傳回。

FalsePart
Object

必要。 Object. 在 Expression 評估為 False 時傳回。

傳回

根據運算式的評估結果,傳回兩個物件當中的其中一個。

範例

這個範例會 IIf 使用 函式來評估 testMe 程序的 參數 checkIt ,如果數量大於 1000,則會傳回 「Large」 這個字,否則會傳回 「Small」 這個字。

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

請注意,如果 是 Option StrictOn,您必須使用 CStr 關鍵字明確地將傳回轉換為 ObjectString

備註

IIf 式提供三元 條件運算符的對應專案:? : 在 Visual C++ 中。

適用於

另請參閱