Frustrated VB.NET programmers who have learned the hard way never to use IIF will be happy to know that someone’s actually fixed that function ( by building a better one ) by modeling C#’s “?:” operator
The new approach is being introduced in Visual Studio 2008 and the story goes a little something like this:
Ol’5×00l
Dim return = IIf(var Is Nothing, foo1(), var.foo())
This seemingly innocent line of code will compile nicely but is guaranteed to come back with a Null Refrence Exception even if var is a valid object.
New’5×00l
Dim return = If(var Is Nothing, foo1(), var.foo())
The new schooler’s will still be using Old’ Faithful, the IF Statement but, with a twist. It now acts as an operator. The best part about it is that it will not execute both sides of the IF as IIF would. The False portion is only executed when the True portion fails.
Read More Here
















var doesn’t exist in VB.BET… I’m going to have to look into this further.