IIf Function in VB.NET
IIF returns one of two objects, depending on the evaluation of an expression.
IIF is a function and it only specific to VB.NET, because in C# there is no IIF, so it is not the part Common Language Runtime. IIf is an alternative to the If...Then...Else statement in VB.NET
Consider the following example :
is same as:
Both statements returns True.
Note :The expressions in the argument list can include function calls.
Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim value As Integer = 190 MsgBox(IIf(value > 100, "higher", "smaller")) ' The following If..Else..statements return the same result If value > 100 Then MsgBox("higher") Else MsgBox("smaller") End If End Sub End Class