Interaction.IIf(Boolean, Object, Object) Method
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
- 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 one of two objects, depending on the evaluation of an expression.
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
.
The IIf
function provides a counterpart for the ternary Conditional Operator: ? : in Visual C++.
Product | Versions |
---|---|
.NET | Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: