Vbnet中是否有空条件运算符? [英] is there a null conditional operator in Vbnet?

查看:56
本文介绍了Vbnet中是否有空条件运算符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中,有一个空条件运算符?.(有时称为Elvis运算符),如下所示:

cIn C# there is a null conditional operator ?. (sometimes called the Elvis operator) like so:

var name = project?.customer?.name;

这不会失败,但是如果 project customer 为null,则返回 null .

which doesn't fail but instead return null if project or customer is null.

VB.NET中是否有等效项?

Is there an equivalent in VB.NET?

请注意,我不是要查找 If(b,x,y) ,但是非常

Note that I am not looking for If(b, x, y) but the very ?. replacement.

推荐答案

VB还具有空条件运算符(从未听说过猫王"运算符):

VB also has the null conditional operator (never heard the term 'Elvis' operator):

Dim name = customer?.name

注意:

  1. 在VB中推断键入要求"Option Infer On"(选择推断开启)

  1. Inferred typing in VB requires 'Option Infer On'

我非常确定您原来的C#代码示例应该是:var name = customer?.name;

I'm pretty sure that your original C# code sample should have been: var name = customer?.name;

这篇关于Vbnet中是否有空条件运算符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆