【发布时间】:2013-05-17 09:55:30
【问题描述】:
VB.NET 等效于 C# ? 运算符是什么?
比如下面的代码怎么写成VB.NET?
hp.pt = iniFile.GetValue("System", "PT").ToUpper().Equals("H") ? PT.PA : PT.SP
【问题讨论】:
VB.NET 等效于 C# ? 运算符是什么?
比如下面的代码怎么写成VB.NET?
hp.pt = iniFile.GetValue("System", "PT").ToUpper().Equals("H") ? PT.PA : PT.SP
【问题讨论】:
从历史上看,IIf 通常用于此目的 - 但它不使用短路,因此并不完全相同。但是,there is now a 3-part If:
hp.pt = If(iniFile.GetValue("System", "PT").ToUpper().Equals("H"), PT.PA, PT.SP)
确实使用短路,因此与 C# 中的 conditional operator 相同。
【讨论】:
您可以使用If operator
hp.pt = If(iniFile.GetValue("System", "PT").ToUpper().Equals("H"), PT.PA, PT.SP)
【讨论】:
尝试像这样使用If 函数:
x = If(condition, trueValue, falseValue)
【讨论】:
此问题与已经提出并回答的问题重复:
Is there a conditional ternary operator in VB.NET?
这里:
Dim foo as String = If(bar = buz, cat, dog)
【讨论】: