== Why is this an issue?

Visual Basic .NET offers a non-short-circuit conditional function, ``++IIf()++``, which returns either its second or third parameter based on the expression in the first parameter. Using it is slower than using ``++If()++`` because each parameter is unconditionally evaluated. Further, its use can lead to runtime exceptions because ``++IIf++`` always evaluates all three of its arguments. 


The newer version, ``++If()++``, should be used instead because it short-circuits the evaluation of its parameters.


=== Noncompliant code example

[source,vbnet]
----
Public Class Foo
    Public Sub Bar() 
        Dim var As Object = IIf(Date.Now.Year = 1999, "Lets party!", "Lets party like it is 1999!") ' Noncompliant
    End Sub 
End Class 
----


=== Compliant solution

[source,vbnet]
----
Public Class Foo 
    Public Sub Bar() 
        Dim var As String = If(Date.Now.Year = 1999, "Lets party!", "Lets party like it is 1999!") 
    End Sub 
End Class 
----


== Resources

* https://msdn.microsoft.com/en-us/library/27ydhh0d(v=vs.90).aspx[IIf Function (MSDN)] 
* https://msdn.microsoft.com/en-us/library/bb513985(v=vs.90).aspx[If Operator (MSDN)]


ifdef::env-github,rspecator-view[]

'''
== Implementation Specification
(visible only on this page)

=== Message

Use the "If" operator here instead of "IIf".


=== Highlighting

``++IIf++``


'''
== Comments And Links
(visible only on this page)

=== on 1 Feb 2017, 13:55:11 Ann Campbell wrote:
\[~valeri.hristov] I've made an editing pass. Please check behind me.

endif::env-github,rspecator-view[]
