I recently learned of the IIF(A,B,C) function. I'm a long time VB/VB.NET Coder who recently spent a lot of time coming up to speed in SQL coding.
One (obvious) common thing to do in SQL is something like the following:
select (case where @var = 0 then MyTable.Val1 else MyTable.Val2 end) from MyTable
IIF(A,B,C) will allow me to do this in VB.NET... all on one line.
However, I have read that both B and C are evaluated no matter what A evaluates to.
I can think of some obvious situations where this is a bad thing such as:
Dim X as integer = IIF(SomeBoolean = true, ExpensiveFunction1(), ExpensiveFunction2())
As I will be including this in my repertoire, are there any more subtle situations where I may get myself into trouble using IIF?
It's a pretty big departure in some situations from using the old fashioned:
Dim X as integer
if SomeBoolean = true then
X = ExpensiveFunction1()
else
X = ExpensiveFunction2()
end if
Thanks in advance for your advice. I'm hoping to save myself some annoying performance issues and/or bugs in the future.