Pros:
- Can return a value, where as an If statement just executes conditional
code. This is a little different
- Convenience, slightly less to type
Cons
- Always returns Object. It is just a function not a language construct, and
so you end up having to cast everything from Object to what it actually is,
even though if it was a compile time check it would be obvious
- Potential performance issues - though i don't know too much about it.
Overall, I would say, unless you have mission critical code, the performance
hit (if any) you will get from IIF is not going to be noticeable in your app
under average usage. It is annoying that the return type as Object, and this
makes IIF a lot less useful then it could have been.
You could always right your own strongly typed IIF, and make it use an If
statemnet (if you are worried about performance).
Public Function IIF(expression as Boolean, truePart as String, falsePart as
String) As String
If expression Then
Return truePart
Else
Return falsePart
End Function
That way you get the convenience of IIF, but improved usability.
You could do this for every type that you commonly use (Integer, etc.).
"SQLScott" <SQ******@discussions.microsoft.com> wrote in message
news:36**********************************@microsof t.com...
I have always heard that using IIF statements is not recommended because
they are slower than using If..Then statements, and not as "clean".
I would appreciate others opinions and why/why not use IIF statements.
--
Thanks,
Scott