I seem to recall something about avoiding the Immediate If operator (?:) in C#, but I don’t know where I read it and what it was. I think it had to do with the fact that both the true and the false part are executed before deciding on the outcome of the condition. Is this correct? Or is this so in VB.Net?
Share
It’s actually called conditional operator and is referred to as ‘?:’ in the MSDN. It is basically a shorthand notation for
if-elseexcept that this is actually expression, not statement. Since it’s equivalent forifthere are no caveats to this operator.What you’ve read is about is possibly about
Iiffunction in VB.NET. Being a function it evaluates all its arguments before being invoked, sowill result in
NullReferenceExceptionbeing thrown.