I am trying to use the IIF in vb.net, here is my code
Dim arr as new MyClass("ABC")
MyAnotherMethod(IIf(arr.SelectedValue.Count < 1, Nothing, arr.SelectedValue(0).Value),"xxx","yyy","zzz")
the above IIF will run into the true part, but after I run this code, I got the following message:
Index was outside the bounds of the array.
I think the reason is that although true part should be run, the arr.SelectedValue(0).Value has passed into the IIF, so the false part is still being referenced.
Does there any logic like “andalso” and suitable for my case? In order to avoid running the false part.
Thanks a lot!
You need to use the IF Operator instead of the IIF Function
“An If operator that is called with three arguments works like an IIf function except that it uses short-circuit evaluation”
It is also type safe whereas IIF is not so you should really be using this. Have a look at these worked examples: