加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

VB.NET空合并运算符?

发布时间:2020-12-17 08:13:07 所属栏目:百科 来源:网络整理
导读:Possible Duplicates: 07000 07001 是否有一个内置的VB.NET等同于C#null合并运算符? 是的,有,只要你使用VB 9或更高版本(包括在Visual Studio 2008)。 您可以使用 If operator重载的版本仅接受两个参数: Dim myVar? As Integer = NothingConsole.WriteLin

Possible Duplicates:
07000
07001

是否有一个内置的VB.NET等同于C#null合并运算符?

是的,有,只要你使用VB 9或更高版本(包括在Visual Studio 2008)。

您可以使用If operator重载的版本仅接受两个参数:

Dim myVar? As Integer = Nothing
Console.WriteLine(If(myVar,7))

更多信息可以在VB.NET团队的博客文章中找到here。

(是的,这是一个运算符,即使它看起来像一个函数,它将编译到与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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读