【发布时间】:2017-06-24 21:37:48
【问题描述】:
在 C# 6 之前,我会编写代码来处理对象,例如:
if (_odbcConnection != null)
{
_odbcConnection.Close();
_odbcConnection.Dispose();
_odbcConnection = null;
}
使用 6,我可以编写更少的代码:
_odbcConnection?.Close();
_odbcConnection?.Dispose();
_odbcConnection = null;
但是这两者是等价的吗?
【问题讨论】:
-
运行你已经写好的代码,自己看看。
标签: c# c#-6.0 null-conditional-operator