[英]vb.net: How is it ? or ?? conditional in c# for vb.net?
在C#中,我們有以下條件賦值:
var test = 1;
var something = (test == 1)? "P":"C";
要么
var test = null;
var something = test ?? "";
是否可以在vb.net中進行?
我正在用C#編程,但是在此項目中,我正在vb.net進行編程,我不記得是否可以這樣做。
它是可以與一個或兩個參數一起使用的If
-operator 。 C#中的空合並運算符( ??
)是帶有一個參數的If
,而條件運算符( ?
)是帶有兩個參數的那個。
“有條件的運營商”
Dim test As Int32 = 1
Dim something As String = If(test = 1, "P", "C")
“空 - 結合運營商”
Dim test As String = Nothing
Dim something As String = If(test, "") ' "" is the replacement value for null '
請注意, If
-operator與舊的IIf
函數不同。 : IIf()和If之間的性能差異
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.