vb.net - = 运算符应用于 VB 中的可空类型
问题描述
我很惊讶在 C# 中:
int? a = null;
int? b = null;
intc = a == b; //c = true
在 VB 中:
Dim a As Integer? = Nothing
Dim b As Integer? = Nothing
if( a = b ) 生成异常,因为条件 a = b 显然被解析为 Nothing(而不是在 C# 中为 true)
我想我可以将我的条件更改为: if( (a Is Nothing AndAlso b Is Nothing) OrElse a = b) 但我觉得这很难看!有没有更优雅的方式来写这个如此简单的条件?
解决方案
推荐阅读
- reactjs - 即使 useState 值已更改,组件也不更新
- node.js - Puppeteer 挂起大型 pdf 生成
- postgresql - PostgreSQL 在通过参数传递时不使用索引
- c# - 来自同一个 httpclient 实例中不同 url 的不同线程的两个请求
- c - 在这种情况下,进程不是总是无法被杀死吗?
- ansible - 当条件 Ansible 不使用 OR 时?
- python - 取消反应后删除角色 Discord.py
- deep-learning - 有没有办法有效地从 fastai.data.core.Dataset 对象中提取所有 PILImages?
- python - 如何根据特定条件将列名添加到行值?
- html - 对 DNS 指向系统感到困惑