【发布时间】:2017-05-11 16:39:53
【问题描述】:
我注意到这篇关于如何对嵌套对象/属性进行内联空值检查的精彩帖子:C# elegant way to check if a property's property is null
是否有可用的 VB.NET 等价物?
【问题讨论】:
-
如果使用最新版本是。和c#一样
标签: vb.net equivalent null-check
我注意到这篇关于如何对嵌套对象/属性进行内联空值检查的精彩帖子:C# elegant way to check if a property's property is null
是否有可用的 VB.NET 等价物?
【问题讨论】:
标签: vb.net equivalent null-check
是的。空条件运算符 (MSDN) 也存在于 VB.NET(VB 14 及更高版本,即 Visual Studio 2015 及更高版本)中,语法相同:
Dim value As Int32? = objectA?.PropertyA?.PropertyB?.PropertyC
通常,这与空合并运算符结合使用,即 C# 中的 a ?? b 和 VB.NET 中的 If(a, b):
Dim value As Int32 = If(objectA?.PropertyA?.PropertyB?.PropertyC, 0) ' Default value if null
【讨论】: