what is the purpose of the iif in vb

早过忘川 提交于 2020-01-06 03:00:29

问题


So, what is the purpose of the iif in vb? I know what it does, but I can't uderstand what is it for?

Update: I know what it does. But "if(,,)" does the same. The only difference is that "Iif" will evaluate both expressions. So what is the purpose of doing this?

Thank you!


回答1:


It allows for a concise boolean logic expression which produces a value

Dim value = Iif(someTest, trueValue, falseValue)

Without the Iif or If operator this has to be expanded into a more combursome set of statements

Dim value;
If someTest Then
  value = trueValue
Else
  value = falseValue
End If



回答2:


If I remember correctly, IIF(a, b, c) returns b if a is true, or c if a is false.




回答3:


There is no need for Iif in new VB.NET code, but has been kept for backward compatibility with existing code.

If you do ever still want Iif, code it yourself as Iif(Of T) at least, so you can avoid the casting that is otherwise required when you have Option Strict On.



来源:https://stackoverflow.com/questions/4431326/what-is-the-purpose-of-the-iif-in-vb

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!