【发布时间】:2011-03-02 15:32:03
【问题描述】:
在我的 Dispose 方法(如下所示)中,每次我想调用 someObj.Dispose() 时,我也会检查 someObj!=null。
那是因为我的设计不好吗? 他们是否是一种更简洁的方法来确定调用对象中使用的所有成员(实现 IDisposable)的 Dispose 而不存在 NullReference 异常的风险?
protected void Dispose(bool disposing)
{
if (disposing)
{
if (_splitTradePopupManager != null)
{
_splitTradePopupManager.Dispose();
}
}
}
感谢您的关注。
【问题讨论】:
标签: c# idisposable nullreferenceexception