当我运行代码分析工具时,我得到以下内容:
Warning 1 CA2000 : Microsoft.Reliability : In method ‘Class1.test.testMethod()’,object ‘dt’ is not disposed along all exception paths. Call System.IDisposable.Dispose on object ‘dt’ before all references to it are out of scope.
How to resolve the warnings??
public void testMethod() { DataTable dt = new DataTable(); DataTable dt1= new DataTable(); try { if (dt.Rows.Count == 0) { dt1.Merge(dt); } } catch { throw; } finally { if (dt != null) dt.Dispose(); if (dt1 != null) dt1.Dispose(); } }