Paul Vick announced a possible change for VB 9.0, this change would give the IIF method the legitimacy it has long deserved. The issue with IIf
is that it’s not a short-circuit operator, which can severely limits its usefulness. Take the following example, that will throw an exception if obj
is Nothing
:
IIf(obj IsNot Nothing, obj.Property1, String.Empty)
Since IIf()
is just a normal method, all parameters will be evaluated, regardless of weather obj
is Nothing
. This change would make IIf
a true part of the language, a true ternary operator, instead of just another method.
IIf
is largely avoided due to performance issues, and its limited usefulness for the reason above. Now that IIf
may function as a true operator (though still wrapped in the cloak of a method), it will be a truly useful part of the language, one that I’ve long wished for. I’ve always been a fan of IIf
, it’ll be nice to be able to use it again, without the overheard and issues that has long went with its use.
Mr. Vick is still soliciting comments on this change, so now is the time to make your opinion known.