在PHP中,您可以在字符串連接中有條件(if/else)。條件內部字符串串聯VB.NET
$string= 'X is' . ($x >0 1 ? ' > 10 ': ' < 10 ')';
在VB.NET中,這是否可行?
在PHP中,您可以在字符串連接中有條件(if/else)。條件內部字符串串聯VB.NET
$string= 'X is' . ($x >0 1 ? ' > 10 ': ' < 10 ')';
在VB.NET中,這是否可行?
您可以使用string inpterpolation和If
-operator:
Dim result = $"X is {If(x > 10, " > 10 ", " <= 10 ")}"
哪個爲String.Format
語法糖:
Dim result = String.Format("X is {0}", If(x > 10, " > 10 ", " <= 10 "))
是的,用繩子插你可以使用表達式 - Interpolated Strings
Dim text = $"IsPositive = {If(number > 0, "true", "false"}"
插值的字符串表達式通過更換 創建一個字符串包含與 表達式結果
的的ToString represenations表達式
VB等效三元運算符的是如果操作者(如從If語句不同)。
您可以直接從PHP到VB翻譯代碼:
Dim test = "X is" & If(x > 10, " > 10 ", " < 10 ")
(我爲源明顯的錯誤一些修正,但我不熟悉PHP的,所以我可能無意中引入差異行爲)。