Possible Duplicates:
07000
07001
是否有一个内置的VB.NET等同于C#null合并运算符?
是的,有,只要你使用VB 9或更高版本(包括在Visual Studio 2008)。
原文链接:https://www.f2er.com/vb/256425.html您可以使用If
operator重载的版本仅接受两个参数:
Dim myVar? As Integer = Nothing Console.WriteLine(If(myVar,7))
(是的,这是一个运算符,即使它看起来像一个函数,它将编译到与C#中的“正确”空聚合运算符相同的IL)。
例
Dim b As Boolean? Console.WriteLine("{0}.",If(b,"this is expected when b is nothing")) 'output: this is expected when b is nothing. b = False Console.WriteLine("{0}.","this is unexpected when b is false")) 'output: False. b = True Console.WriteLine("{0}.","this is unexpected when b is true")) 'output: True.