Net-informations.com
SiteMap  | About    

IIf Function in VB.NET

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

  IIf(Expression As Boolean,TruePart As Object,FalsePart As Object) As Object

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 :

  If 10 > 9 Then
	MsgBox("True")
  Else
	MsgBox("False")
  End If

is same as

  MsgBox(IIf(10 > 9, "True", "False"))

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






net-informations.com (C) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.