VB.NET 中是否有条件三元运算符? [英] Is there a conditional ternary operator in VB.NET?
本文介绍了VB.NET 中是否有条件三元运算符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 Perl(和其他语言)中,条件三元运算符可以这样表示:
In Perl (and other languages) a conditional ternary operator can be expressed like this:
my $foo = $bar == $buz ? $cat : $dog;
VB.NET 中是否有类似的运算符?
Is there a similar operator in VB.NET?
推荐答案
取决于版本.VB.NET 2008 中的 If
运算符是三元运算符(以及空合并运算符).这是刚刚推出的,在 2008 年之前这是不可用的.以下是更多信息:Visual Basic If 公告
Depends upon the version. The If
operator in VB.NET 2008 is a ternary operator (as well as a null coalescence operator). This was just introduced, prior to 2008 this was not available. Here's some more info: Visual Basic If announcement
示例:
Dim foo as String = If(bar = buz, cat, dog)
在 2008 年之前,它是 IIf
,其工作方式几乎与上述 If
运算符相同.
Prior to 2008 it was IIf
, which worked almost identically to the If
operator described Above.
示例:
Dim foo as String = IIf(bar = buz, cat, dog)
这篇关于VB.NET 中是否有条件三元运算符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文